mercredi 25 septembre 2019

I was trying to update the Auth::user() and his profile. But having no error not even having any changes to the database

I was using two tables ... Default user and profile table for the users. And i was trying to make a profile updating option.I did all the code needed to be done. But having no changes to the profile table not even in the user table.

Here is the code......

namespace App\Http\Controllers;

use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth;

class ProfileController extends Controller {

public function index()
{
    return view('admin.users.profile')->with('user',Auth::user());
}


public function update(Request $request)
{
    //dd($request);

    $this->validate($request, [
        'name'  => 'required',
        'email' => 'required|email',
        'password'=> 'required',
        'about'   => 'required',
        'facebook'=> 'required|url'
    ]);

            $user = Auth::user();

            if($request->hasFile('avatar')){

                $received_image = $request->avatar;
                $updated_name = time().$received_image->getCilentOriginalName();
                $received_image->move('uploads/avatar',$updated_name);

                $user->profile->avatar = 'uploads/avatar'.$updated_name;

                $user->profile->save();
            }


                $user->name = $request->name;
                $user->email = $request->email;

                $user->profile->facebook = $request->facebook;
                //$user->profile->youtube = $request->youtbe;
                $user->profile->about = $request->about;

                $user->save();
                $user->profile->save();


            if($request->has('password'))
                {
                    $user->password = bcrypt($request->password);
                    $user->save();

                }



                session()->flash('success', 'Profile Updated Successfully');

                return redirect()->back();
}

}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire