vendredi 22 novembre 2019

Find user with username in Laravel?

Two relational tables are there User and Profile and the user name stored in profile.I pass the username in route and used this code for getting the user but its showing me an error

"Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function profile() on null in file ". What wrong in this code please check!!

public function update(Request $request,$user)
    {
        $user = User::find(1)->profile()->where('username',$user);
        $user->update([
        'name'=> $request->name,
        'email'=> $request->email
    ]);
    // A User has a profile
    $user->profile()->update([
        'username'=> $request->username,
        'location'=> $request->location,
        'languages'=> $request->languages,
        'about'=> $request->about,
        'skills'=> $request->skills,
        'available_for'=> $request->available_for

   ]);


    return [
        'status' => true,
        'message' => 'User and profile upated',
    ];


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire