nyaabooru/app/Livewire/PostFeature.php

33 lines
521 B
PHP

<?php
namespace App\Livewire;
use App\Models\Post;
use Livewire\Component;
class PostFeature extends Component
{
public ?Post $post = null;
public function mount()
{
$this->post = Post::raw(function($collection)
{
return $collection->aggregate([
['$match' => ['featured' => 'on']],
['$sample' => ['size' => 1]]
]);
})->first();
}
public function render()
{
if ($this->post == null)
{
return <<<'HTML'
<div></div>
HTML;
}
return view('livewire.post-feature');
}
}