mercredi 18 septembre 2019

laravel 5.8: show empty fields to a new user in profile page

I am setting up profile section.

I want to show empty fields to a new user.

First I tried this, but it didn't work because new user's profile table is empty.

<li>Name :<br>
    <p>
      
    </p>
 </li>

So next I tried this one.

<p>@if(!empty(Auth::user()->profile->name))
      
    @endif</p>

It worked, I could see an empty field with no error. But after I inserted a 'name' and redirect to index.blade.php page, 'name' didn't show up, still empty.

I want to see a profile page filled with user profile information.

Then, lastly, I tried this.

@if($profile->count() > 0)
    <ul class="information">
        <li>Name :<br>
           <p>
             
           </p>
         </li><br>
@endif

but I got an error Undefined variable: profile.

UserController.php

public function store(Request $request) {

        $this->validate($request,[
            'name' => 'required'
        ]);

        $profile = new Profile;

        $profile->name = $request->input('name');

        $profile->save();

        return redirect()->route('profile.index');

    }

web.php

Route::prefix('user')->group(function(){
    Route::resource('profile', 'UserController');
});

also I want to show profile information to an edit page.

I am glad if someone helps me out.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire