vendredi 1 novembre 2019

Right Nav Bar error, Not authenticate in Laravel

In my web-app i made a profile section . But the problem is when it goes to dashboard in right-navbar it has my profile and logout. when i click on my profile-> in my profile page the right-navbar became register and sign in instead of name and logout. I think some authentication issue is there. please suggest how to fix it. check screenshots also for better understanding.

enter image description here

enter image description here

app.blade.php

    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <!-- Left Side Of Navbar -->
        <ul class="navbar-nav mr-auto">

        </ul>

        <!-- Right Side Of Navbar -->
        <ul class="navbar-nav ml-auto">
            <!-- Authentication Links -->
            @guest
                <li class="nav-item">
                    <a class="nav-link" href=""></a>
                </li>
                @if (Route::has('register'))
                    <li class="nav-item">
                        <a class="nav-link" href=""></a>
                    </li>
                @endif
            @else
                <li class="nav-item dropdown">
                    <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
                         <span class="caret"></span>
                    </a>

                    <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">

                        @auth
                        <a class="dropdown-item" href="">
                             My Profile
                         </a>
                         @endauth
                        <a class="dropdown-item" href=""
                           onclick="event.preventDefault();
                                         document.getElementById('logout-form').submit();">
                            
                        </a>

                        <form id="logout-form" action="" method="POST" style="display: none;">
                            @csrf
                        </form>
                    </div>
                </li>
            @endguest
        </ul>
    </div>
</div>

profiles/show.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">
                    

                </div>
                <div class="card-body">
                    <form id="update-profile-form" action="" method="POST" enctype="multipart/form-data">
                        @csrf

                        @method('PATCH')
                        <div class="form-group row justify-content-center">
                            <div class='profile-avatar'>
                                <div onclick="document.getElementById('image').click()" class="profile-avatar-overlay">
                                    <svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 32 32">

                                        <path d="M18 22.082v-1.649c2.203-1.241 4-4.337 4-7.432 0-4.971 0-9-6-9s-6 4.029-6 9c0 3.096 1.797 6.191 4 7.432v1.649c-6.784 0.555-12 3.888-12 7.918h28c0-4.030-5.216-7.364-12-7.918z"></path>
                                        </svg>

                                </div>
                                <img src="" alt="" >

                            </div>
                        </div>

                        <input onchange="document.getElementById('update-profile-form').submit()" style="display: none;" id="image" type="file" name="image">

                        <div class="form-group">

                            <label for="name" class="form-control-label">

                                Name

                            </label>

                            <input id="name" name="name" value="" type="text" class="form-control">

                        </div> 

                        <div class="form-group">
                                <label for="description" class="form-control-label">

                                    Description

                                </label>

                                <textarea name="description" id="description"  rows="3" class="form-control"></textarea>


                            </div>

                            <button type="submit" class="btn btn-info">
                                    update profile
                            </button>
                    </form>


                </div>
            </div>
        </div>
    </div>
</div>
@endsection

ProfileController.php

class ProfileController extends Controller
{

    public function show(Profile $profile)
    {

        return view('profiles.show', compact('profile'));
    }


    public function update(Request $request, Profile $profile)
    {
        if ($request->hasFile('image'))
        {
            $profile->clearMediaCollection('images');

            $profile->addMediaFromRequest('image')
                     ->toMediaCollection('images');

        }
        return redirect()->back();
    }


}


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire