43 lines
1 KiB
PHP
43 lines
1 KiB
PHP
<?php
|
|
|
|
namespace App\View\Components;
|
|
|
|
use Illuminate\View\Component;
|
|
use App\Recipe;
|
|
|
|
class RecipeWidget extends Component
|
|
{
|
|
private $limit;
|
|
private $recipes;
|
|
private $id;
|
|
|
|
/**
|
|
* Create a new component instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct($limit, $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'));
|
|
}
|
|
}
|