Find User in Laravel by Username
问题 So typically 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; 回答1: Yes, even better using the model. just like this User::where('username','John') -> first(); // or