On laravel/livewire site I read data with possible eager loading of tags :
$this->postList = Post
::orderBy('title')
->with('tags')
->getByTitle('%search%')
->select('id', 'post_category_id', 'title', 'slug', 'image', 'published', 'created_at', 'creator_id')
->paginate(10)
->through(function ($postItem) {
$postItem->image = (new CheckModelImage())->get($postItem->image, get_class($postItem));
return $postItem;
});
and in template file I call other component with tags parameter passed:
@livewire('model-tag', ['id'=>$post->id, 'tags' => $post->tags], key($post->id))
If in top request there are no tags eager parameter used in which way can I to check it ?
I tried to check inside of model-ag component using isset method:
class ModelTag extends Component
{
use AppCommonTrait;
public int $id;
public $tags;
public $modelTaggables = [];
public function render(): View
{
return view('livewire.model-tag');
}
public function mount(int $id, ?IlluminateDatabaseEloquentCollection $tags = null)
{
$this->id = $id;
$this->tags = $tags;
$this->getData();
}
protected function getData(): void
{
if(isset($this->tags)) { // I CHECK HERE _ BUT IT ALWAYS VALID
$this->modelTaggables = $this->tags;
} else {
$this->modelTaggables = Taggable
->getByTaggableId($this->id)
->with('tag')
->get()
->map(function ($TaggableItem) {
return ['id' => $TaggableItem->tag_id, 'name' => $TaggableItem->tag->name];
});
}
}
}
I search method like whenLoaded in resources…
Are there ?
"laravel/framework": "^10.48.7",
"livewire/livewire": "^3.4.10",
Thanks in advance!