lundi 16 novembre 2020

Search in the related model in Laravel

I have post table like this :

id | post_title | category_id

and this is category table

id | category_title

this is the relation between these two which is inside post model :

  public function category()
    {
        return $this->belongsTo(Category::class, 'category_id', 'id');
    }

I want to get the record of post table where category_title or post_title matches the keyword entered by user.

I'm retrieving data something like:

Post::where(['title'=>$request->title])->with('category')->paginate(10);

but here it is only fetching Post title but i also want it to search it in category title.

Any help is highly appreciated.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2UtCgaj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire