63 lines
1.3 KiB
PHP
63 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\View\Components;
|
|
|
|
use Illuminate\View\Component;
|
|
use App\Recipe;
|
|
|
|
class RecipeWidget extends Component
|
|
{
|
|
/**
|
|
* limit variable
|
|
*
|
|
* @var mixed
|
|
*/
|
|
private $limit;
|
|
|
|
/**
|
|
* id variable
|
|
*
|
|
* @var mixed
|
|
*/
|
|
private $id;
|
|
|
|
/**
|
|
* recipes variable
|
|
*
|
|
* @var \App\Recipe
|
|
*/
|
|
private $recipes;
|
|
|
|
/**
|
|
* Create a new component instance.
|
|
*
|
|
* @param mixed $limit
|
|
* @param mixed $id
|
|
* @return void
|
|
*/
|
|
public function __construct(mixed $limit, mixed $id = null)
|
|
{
|
|
$this->limit = 3;
|
|
if ($limit != null) {
|
|
$this->limit = $limit;
|
|
}
|
|
if ($id != null) {
|
|
$this->id = $id;
|
|
$this->recipes = Recipe::where('live', '1')
|
|
->where('id', '!=', $this->id)->inRandomOrder()->limit($this->limit)->get();
|
|
} else {
|
|
$this->recipes = Recipe::where('live', '1')->inRandomOrder()->limit($this->limit)->get();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Get the view / contents that represent the component.
|
|
*
|
|
* @return \Illuminate\Contracts\View\View|\Closure|string
|
|
*/
|
|
public function render()
|
|
{
|
|
$recipes = $this->recipes;
|
|
return view('components.recipe-widget', compact('recipes'));
|
|
}
|
|
}
|