96600/how-to-find-user-in-laravel-by-username
if you have access to the id of a user in laravel you can run User::find($id), however say you don't have access to the user's id and only their username. Is there a better way than using DB::query to locate the user?
This is my current solution and was wondering if someone possibly knew a better way.
$user_id = DB::table('users')->where('username', $user_input)->first()->id;
Hello,
using the model. just like this
User::where('username','John') -> first(); // or use like User::where('username','like','%John%') -> first(); User::where('username','like','%John') -> first(); User::where('username','like','Jo%') -> first();
Hello @kartik, Use middleware for this purpose and ...READ MORE
Hii, Use order by like this: return User::orderBy('name', 'DESC') ...READ MORE
Hello @kartik, You can update the cache object ...READ MORE
Hello @kartik, You can use it in middleware. ...READ MORE
Hey @kartik, First you have to go to ...READ MORE
Named route is used to give specific ...READ MORE
Hello, This is simple you just need to ...READ MORE
Hey @kartik, Named routing is another amazing feature of ...READ MORE
Hello @kartik, One of the methods it provides ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.