haheute
haheute

Reputation: 2199

How to select Eloquent model without arguments

I don't know if 'arguments' is the right term. I want to get a model without everything and add the selects and wheres later.

$query = Pic::;

if($cat) $query->where('cat',$cat);
if($year) $query->where('jahrprod',$year);

$query->get();

Pic:: or Pic don't work. Only DB::table('pics') does, but does not seem to return a collection.

Upvotes: 0

Views: 429

Answers (1)

Pawel Bieszczad
Pawel Bieszczad

Reputation: 13325

Use Model::query();

$query = Pic::query();

if($cat) $query->where('cat',$cat);
if($year) $query->where('jahrprod',$year);

$query->get();

Upvotes: 1

Related Questions