kiasaty
6 months ago

problem in searching using book's author - eloquent relationships

Posted 6 months ago by kiasaty

I'm using the code below (as the document says) to search books by author's name.

function Show(Book $books, Request $request, Author $authors) $data['books'] = $books->with(['author' => function ($query) { $query->where('authors.name', 'like', "%geo%"); dump($query); }])->get(); }

but it doesn't work. it turns back all the authors.

Models:

class Author extends Model { // public function book() { return $this->belongsTo('App/Book', 'authorID', 'id'); } }

class Book extends Model { // function author() { return $this->hasOne('App\Author', 'id', 'authorID'); } }

please help me fix this.

Please sign in or create an account to participate in this conversation.