Support the ongoing development of →
Requests Views
Last updated 2 years ago.

Can you show us your view? That is where your error is occurring.

Assumption being made: With courses being plural, you should probably be using get instead of first to get all of the courses and not just the first one.

$courses = DB::table('courses')->where('user_id', '1')->get();

If you want to use Auth::user()->id you can use a before filter on your route to make sure the user is logged in.

Last updated 2 years ago.


Actually, yeh, it was the get problem. Nice one.

I already have the filter on to make sure a user can't see the page until they're logged in. However, how would I pass the logged in user's user_id to the query to replace:

->where('user_id', '1')

So basically

$course = DB:table('courses')->***Logged in User***->get();

Thanks for your help! Marc

Last updated 2 years ago.

@themarcthomas try

$courses = DB::table('courses')->where('user_id', Auth::user()->id )->get();

assuming your using laravel's auth system

Last updated 2 years ago.

@taftse — thanks. That worked.

The mists of learning Laravel are quickly evaporating!


Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?


We'd like to thank these amazing companies for supporting us

Your logo here?

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 - All rights reserved.