mercredi 29 août 2018

How do I query two related models in Laravel

I'm stucked on a Laravel blog project I'm working on & will appreciate any assistance. I have 2 related models, User and Post, & then in my blade file a search form which will query both models for result. In my Controller method, I have:

    $q = $request->keyword;
    $results = Post::where ('title', 'LIKE', '%{$q}%')->orWhere('body', 'LIKE', '%{$q}%')->with(['user' => function($x){
        $x->orWhere('name',  'LIKE', '%{$q}%')->get();
    }])->get();
return view('result')->withResults($results);

Issue is i dont get a response in my blade file. I suspect there's a bug in my controller method but I just can't wrap my head around it. I am using Laravel 5.4



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

Aucun commentaire:

Enregistrer un commentaire