I'm using query scope within my controllers in some places but now i'm trying to filter down some results within my blade template. My model has a location which has orders. I pass the location to the blade template and then use the following:
@foreach( $location->orders->datesearch('delivered_at','2015-10-01','2015-10-15') as $order )
{{ $order->order_number }}<br />
@endforeach
And here's an excerpt from my Order Model
class Order extends Model {
public function location()
{
return $this->belongsTo('App\Location', 'location_id');
}
public function scopeDatesearch($query,$datesearch,$search_date_start,$search_date_end)
{
return $query->whereBetween($datesearch, [$search_date_start, $search_date_end])->get();
}
}
Location hasMany Orders as well.
The error I'm getting is:
FatalErrorException in 56b3a0ff15f6ddc28458248fd0728a27 line 5:
Call to undefined method Illuminate\Database\Eloquent\Collection::datesearch()
I did find this similar posting which seems to indicate what I'm doing should work.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire