ErrorException Invalid argument supplied for foreach(),Here what i am trying. I can get it working when call all sort methods in controller rather then caliing a sortitems method.
ErrorException Invalid argument supplied for foreach()
// Controller
$items = Item::sortItems($orderBy);
// Model
static function sortItems($orderBy)
{
if($orderBy == 'popular'){
DB::table('items')->orderby('views','desc')->paginate(50);
}
elseif ($orderBy == 'lowest-price'){
DB::table('items')->orderby('price','asc')->paginate(50);
}
elseif ($orderBy == 'highest-price'){
DB::table('items')->orderby('price','desc')->paginate(50);
}
else{
DB::table('items')->orderby('id','desc')->paginate(50);
}
}
// View
@foreach($items as $row)
@endforeach
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire