Eloquent relationship as below:
"stores" belongs to many "storedaytimes" (belong to many)
The pivot table (store_day_time_stores) has a key called "user_id", the storedaytimes table has a field called "date".
I want to filter records in "storedaytimes" based on given "user_id(from pivot table)" and a "start" and "end" date(from storedaytime table).
My current query is
$storedaytime->stores()
->wherePivot('user_id','=',$user)
->orderBy('date')
->where('date','>=',$start)
->where('date','<=',$end)->get();
It's producing a very scary looking query that's not working:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'date' in 'where clause' (SQL: select
stores.*,order_day_time_store.order_day_time_idaspivot_order_day_time_id,order_day_time_store.store_idaspivot_store_id,order_day_time_store.user_idaspivot_user_id,order_day_time_store.idaspivot_idfromstoresinner joinorder_day_time_storeonstores.id=order_day_time_store.store_idwhereorder_day_time_store.order_day_time_idis null andorder_day_time_store.user_id= 4 anddate>= 2017-05-01 12:00:00 anddate<= 2017-05-31 12:00:00 order bydateasc)
Please help.thank you :3