mardi 12 janvier 2016

Laravel 5.2 Eloquent ORM ::with including a function for where does not work

I want to filter my content elements and have the following code in my controller.

 public function filter ($type, $field){


    $contents = Content::with(array('user' => function($query) use ($type,$field){

        if($type != "all"){
            $query->where('type','=',$type);
        }
        if($field != 'all'){
            $query->where('field','=',$field);
        }

    }))->active()->take(50);



    return view('contents.index', compact('contents'));
}

I always get an empty result. Anyone?

Thank you! :)



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire