Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

Is it possible to use Auth with query builder DB::table?

I want to query some table but also make sure the user is authenticated

is it possible to use both Auth and DB::table? Or do something that would be equivalent to that?

because I want to create an accessor for the User which gets data from another table:

DB::table('table')->where('id', some_id)->value('colum');

I was thinking about:

DB::table('table')->where('id', Auth::user()->id)->value('colum');

Will that be equivalent?

Thanks

0 likes
2 replies
axeloz's avatar
axeloz
Best Answer
Level 2

@ligonsker I would rather do a

if (Auth::check()) {
		DB::table('table')->where('id', Auth::id())->value('colum');
}
1 like

Please or to participate in this conversation.