Support the ongoing development of Laravel.io →
Requests Views
Last updated 1 year ago.
0

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 1 year ago.
0

Hey,

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 1 year ago.
0

@themarcthomas try

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

assuming your using laravel's auth system

Last updated 1 year ago.
0

@taftse — thanks. That worked.

The mists of learning Laravel are quickly evaporating!

Marc

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

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

Your logo here?

Laravel.io

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

© 2024 Laravel.io - All rights reserved.