lundi 26 février 2018

Laravel - Fetch data using Auth

I want to fetch information of the logged in user stored in the database that is to be shown on his profile page. At the time of registration, he/she is been asked to enter the data and only a few fields are mandatory but in the 'edit profile' page he/she can add more information and then return to his profile page, where all the data should be updated. But the problem here is that only name and email is been fetched.

Controller code:

public function updateProfile(Request $req) {
        $name = Auth::user()->name;
        $user = Admin::where('name', $name)->first();
        if($req->input('admin-name')!= null) {
            $user->name = $req->input('admin-name');

        }

        if($req->input('admin-email')!= null) {
            $user->email = $req->input('admin-email');
        }
        if($req->input('admin-address')!= null) {
            $user->address = $req->input('admin-address');
        }
        if($req->input('admin-mobile')!= null) {
            $user->mobile = $req->input('admin-mobile');
        }
        if($req->input('admin-dob')!= null) {
            $user->dob = $req->input('admin-dob');
        }


        $user->save();


        return redirect('admin-profile')->with('update-response','Profile Updated successfully');
}

View:

<div class="col-sm-6 col-md-8">
                    <h4>
                    </h4>
                    <small><cite title=""> <i class="glyphicon glyphicon-map-marker">
                    </i></cite></small>
                    <p>
                        <i class="glyphicon glyphicon-envelope"></i>
                        <br />
                        <i class="glyphicon glyphicon-globe"></i>Contact: 
                        <br />
                        <i class="glyphicon glyphicon-gift"></i>Born at </p>    
                </div>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire