ldc-wenn-dann-mit-respekt/app/View/Components/RecipeWidget.php

64 lines
1.3 KiB
PHP
Raw Normal View History

2022-11-18 12:39:03 +01:00
<?php
namespace App\View\Components;
use Illuminate\View\Component;
use App\Recipe;
class RecipeWidget extends Component
{
2022-12-23 17:24:09 +00:00
/**
* limit variable
*
* @var mixed
*/
2022-11-18 12:39:03 +01:00
private $limit;
2022-11-18 15:35:39 +01:00
2022-12-23 17:24:09 +00:00
/**
* id variable
*
* @var mixed
*/
2022-11-18 12:39:03 +01:00
private $id;
2022-12-23 17:24:09 +00:00
/**
* recipes variable
*
* @var \App\Recipe
*/
private $recipes;
2022-11-18 12:39:03 +01:00
/**
* Create a new component instance.
*
2022-12-23 17:24:09 +00:00
* @param mixed $limit
* @param mixed $id
2022-11-18 12:39:03 +01:00
* @return void
*/
2022-12-23 17:24:09 +00:00
public function __construct(mixed $limit, mixed $id = null)
2022-11-18 12:39:03 +01:00
{
2022-12-23 17:24:09 +00:00
$this->limit = 3;
2022-11-18 15:35:39 +01:00
if ($limit != null) {
$this->limit = $limit;
}
if ($id != null) {
$this->id = $id;
2022-12-23 17:24:09 +00:00
$this->recipes = Recipe::where('live', '1')
->where('id', '!=', $this->id)->inRandomOrder()->limit($this->limit)->get();
2022-11-18 15:35:39 +01:00
} else {
2022-11-18 12:39:03 +01:00
$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'));
}
}