So in this project I have homepage which is showing only posts that are made that day. And right now I need my price summing for that day and for that I add this to my price summing code
In my home.blade.php for summing price :
<tfoot>
<tr>
<th>UKUPAN IZNOS: {{ Auth::user()->posts->whereDate('created_at','=',$date)->sum('cijena') }}€</th>
<th>KARTICA: {{ Auth::user()->posts->where('placanje', 'Kartica')->whereDate('created_at','=',$date)->sum('cijena')}}€</th>
<th>GOTOVINA: {{ Auth::user()->posts->where('placanje', 'Gotovina')->whereDate('created_at','=',$date)->sum('cijena')}}€</th>
<th>VIRMAN: {{ Auth::user()->posts->where('placanje', 'Virman')->whereDate('created_at','=',$date)->sum('cijena')}}€</th>
<th>NK: {{ Auth::user()->posts->where('placanje', 'NK')->whereDate('created_at','=',$date)->sum('cijena')}}€</th>
</tr>
</tfoot>
And this whereDate method is from my HomeController and here it is:
public function index()
{
$date = new Carbon(request('date'));
$posts = Post::where('user_id', Auth::id())
->whereDate('created_at','=',$date)
->orderBy('created_at', 'DESC')
->paginate(30); //add {{ $posts->links() }} if paginate is enabled
return view('home', compact('date', $date))->with('posts', $posts);
}
And my route in web.php is:
Route::get('/home', 'HomeController@index')->name('home');
And all it returns me is that method whereDate does not exist. Any ideas how to fix this?
->posts: you should useAuth::user()->posts()->...- dparoliAuth::user()->id- user6854465