mardi 10 septembre 2019

Object of class Illuminate\Database\Eloquent\Builder could not be converted to string in filtering

I'm making search functionality, and like to add filter my search and my code is like

CODE AREA =========================================================

public function search(Request $request) {

    $q = $request->input('q');

    $resources = Resource::where('title','LIKE','%'.$q.'%')

                    ->orWhere('name','LIKE','%'.$q.'%')

                    ->orWhere('batch','LIKE','%'.$q.'%')

                    ->orWhere('mba/emba','LIKE','%'.$q.'%')

                    ->orWhere('topic','LIKE','%'.$q.'%')

                    ->orWhere('year','LIKE','%'.$q.'%')

                    ->orWhere('company','LIKE','%'.$q.'%')

                    ->orWhere('supervisor','LIKE','%'.$q.'%')

                    ->orWhere('abstract','LIKE','%'.$q.'%') 

                    ->latest()->paginate(5);
    if(count($resources) > 0) {

        return view('blog', [

            'resources' => $resources

        ]);

    }else {

         echo "there is nothing like that result";

    }

}

I'm search with an input value and I would like to filter and i change my code like that.... so I can filter from existing Query

CODE AREA============================================================

 public function search(Request $request) {

    $q = $request->q;

    $resources = Resource::where('title','LIKE','%'.$q.'%')

                    ->orWhere('name','LIKE','%'.$q.'%')

                    ->orWhere('batch','LIKE','%'.$q.'%')

                    ->orWhere('mba/emba','LIKE','%'.$q.'%')

                    ->orWhere('topic','LIKE','%'.$q.'%')

                    ->orWhere('year','LIKE','%'.$q.'%')

                    ->orWhere('company','LIKE','%'.$q.'%')

                    ->orWhere('supervisor','LIKE','%'.$q.'%')

                    ->orWhere('abstract','LIKE','%'.$q.'%');

    $author = $request->author;

    if($author != '') {


        //"This is where the error message show"
        //"I would like to filter from above query"
        =======================================================
        $resources = $this->$resources->where('name', $author) 
        =======================================================
        dd($resources);
    }

    $resources = $resources->latest()->paginate(5);               
    if(count($resources) > 0) {
        return view('blog', [
            'resources' => $resources
        ]);
    }else {
         echo "there is nothing like that result";
    }
}

And so, I'm end up with getting message => "Object of class Illuminate\Database\Eloquent\Builder could not be converted to string"

and i'm noob...so plz help....and thank you all



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire