ldc-wenn-dann-mit-respekt/app/View/Components/RecipeWidget.php
Noah Lancien 222347d890 phpstan
2024-01-29 16:20:14 +01:00

63 lines
1.4 KiB
PHP

<?php
namespace App\View\Components;
use Illuminate\View\Component;
use App\Models\Recipe;
class RecipeWidget extends Component
{
/**
* limit variable
*
* @var mixed
*/
private $limit;
/**
* id variable
*
* @var mixed
*/
private $id;
/**
* recipes variable
*
* @var \Illuminate\Database\Eloquent\Collection<\App\Models\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::query()->where('status', '1')
->where('id', '!=', $this->id)->inRandomOrder()->limit($this->limit)->get();
} else {
$this->recipes = Recipe::query()->where('status', '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('fo.components.recipe-widget', compact('recipes'));
}
}