- Laravel Version: 5.3.28
- PHP Version: 7.0.10
- Database Driver & Version: MySQL 5.7.14
I got an error ,When i try to use whereDate in my view page.
1/2 BadMethodCallException in Macroable.php line 74: Method whereDate does not exist.
2/2 ErrorException in Macroable.php line 74: Method whereDate does not exist. (View: C:\wamp\www\2_Work\dashboard\resources\views\pdf\user.blade.php)
My model relationship is work, But why i can't use whereDate function.
@extends('layouts.pdf')
@section('content')
<table border="1" cellspacing="0" cellpadding="0" width="545">
<tr>
<th>ชื่อผู้ใช้งาน</th>
<th>เข้าใช้ล่าสุด</th>
<th>จำนวนการเข้าใช้งานใน 7 วัน</th>
<th>จำนวนงานที่ทำในวันที่ 13/01/2560</th>
</tr>
@foreach ($users as $user)
<tr>
<td><span class="td-text">{{$user->user_detail}}</span></td>
<td align="center">{{$user->ual->first()->created_at ?? NULL}}</td>
<td align="center">{{$user->ual->where('created_at', '>=', '(CURDATE() - INTERVAL 7 DAY)')->count()}}</td>
<td align="left"><?php var_dump( $user->dataDetail->whereDate('created_at', '2017-01-13')->toArray() ); ?></td>
</tr>
@endforeach
</table>
@endsection
Controller
$data['users'] = UserModel::all();
return view('pdf.user', $data);
UserModel
class UserModel extends Model
{
public function dataDetail()
{
return $this->hasMany('App\DataDetailModel', 'user_id', 'user_id');
}
}
$user->dataDetail
? – CUGreen$user->dataDetail()->whereDate('created_at', '2017-01-13')->toArray();
? – CUGreen$user->dataDetail()->whereDate('created_at', '2017-01-13')->get()->toArray();
Thank you very much. – ThunderBirdsX3