dropdown menu doesn't open - laravel 5 - php

I can not get out of my application, I'm using the auth out of box login for laravel 5, but when I get out of my account, I'm not successful.
EDIT: the problem is that dropdown menu does not open for me to logout.
Can someone help me ?
this is my app.blade.php ->
#guest
<li>Login</li>
<li>Register</li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false" aria-haspopup="true" v-pre>
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endguest

#theFlash So CSS is setting the logout button to style="display: none" you need to set this to either display: block;, display: inline-block; or display: inline; to get it to show up. At the moment it's hidden by CSS so you can't click it...

Adding app.js file helped me to open the dropdown
//app.blade.php
<script src="{{ asset('js/app.js') }}"></script>

Related

why logout don't show and i creat it with bootstrap auth in laravel?

here is the nav bar but the code is :
#else
<a id="navbarDropdown" class="nav-element" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false" v-pre>
{{ Auth::user()->name }}
</a>
<div class="dropdown-menu dropdown-menu-end" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
#csrf
</form>
</div>
</li>
#endguest
i can't logout
{{ __('Logout') }}
this div don't showed
I don't think you could use {{ __('Logout') }} as is. You may use {{ $Logout }} instead. To indicate that it came from a function in your file.
The code you pasted here is coming under #guest. So it will not show up if you are logged in. There will be a menu in your code for authenticated users add logout there

View [login] not found

I'm working on a Laravel project and I added a link to log out in my sidebar
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Se déconnecter') }}
</a>
<form id="logout-form" action="{{ ('logout') }}" method="POST" style="display: none;">
#csrf
</form>
but Once I click on the link I get View [login] not found.
can you help ?
Update
update 2
I put the logout link in the view of my sidebar
<div class="navbar-default sidebar" role="navigation">
<div class="sidebar-nav navbar-collapse">
<ul class="nav" id="side-menu">
<li>
<i class="fa fa-dashboard fa-fw"></i> Dashboard
</li>
<li>
<i class="fa fa-bar-chart-o fa-fw"></i> After sales & Parts<span class="fa arrow fa-fw"></span>
<ul class="nav nav-second-level">
<li>
Obeya
</li>
<li>
Parts
</li>
</ul>
<!-- /.nav-second-level -->
</li>
<li>
<i class="fa fa-usd fa-fw"></i> Finances
</li>
<li>
<i class="fa fa-lg fa-cog fa-fw"></i> Paramétrages
</li>
<li>
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
<i class="fa fa-sign-out fa-fw"></i>
{{ __('Se déconnecter') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
</li>
</ul>
</div>
<!-- /.sidebar-collapse -->
I think you missed route function in your form!
You should change:
<form id="logout-form" action="{{ ('logout') }}" method="POST" style="display: none;">
#csrf
</form>
to
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
#csrf
</form>
For more details check Auth Code
UPDATE:
OP was redirecting to login view after logout but OP didn't called the view correctly in his routes.
In OP web.php the return code was like:
return view('login');
So after changing the above code to below it started working
return view('auth.login');
Because when we run php artisan make:auth, the login and other files are inside auth directory!
you have to name your route as "login"
example
Route::get('/userlogin',['as'=>'login','uses'=>'yourcontroller#yourmethod']);
or
Route::get('/userlogin', function () {
//
})->name('login');

Toggle Dropdown not working?

I am doing a project in which I show users and when any person click on that user it should has to do a particular task and that is, it has to show a dropdown as written in code
But when I click on the username nothing happens, is just a simple click, it is not showing the dropdown
<div class="navbar-custom-menu">
<ul class="nav navbar-nav">
<!-- User Account: style can be found in dropdown.less -->
<li class="dropdown user user-menu">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<img src="dist/img/user2-160x160.jpg" class="user-image" alt="User Image">
<span class="hidden-xs">{{ Auth::user()->name }}</span>
</a>
<ul class="dropdown-menu">
<!-- User image -->
<li class="user-header">
<img src="dist/img/user2-160x160.jpg" class="img-circle" alt="User Image">
<p>
{{ Auth::user()->name }} - Web Developer
<small>Member since {{ Auth::user()->created_at->toFormattedDateString() }}</small>
</p>
</li>
<!-- Menu Footer-->
<li class="user-footer">
<div class="pull-left">
Profile
</div>
<div class="btn btn-default pull-right">
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</div>
</li>
</ul>
</li>
</ul>
</div>
i think you might be missing your java script code that performs the toggle function itself. your link has the class=dropdown-toggle but nothing to help display the information you want to show.

Laravel hasRole() error while creating user management

I am new to laravel5.4. By using this url i am trying to make user management. After installing everything i got below error. Please help this out to fix this error
(3/3) ErrorException
Call to undefined method Illuminate\Database\Query\Builder::hasRole() (View: /var/www/html/laravel5/resources/views/layouts/app.blade.php) (View: /var/www/html/laravel5/resources/views/layouts/app.blade.php)
My layout app.blade.php is as below
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
#if (Auth::guest())
<li>Login</li>
<li>Register</li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
#role('Admin') {{-- Laravel-permission blade helper --}}
<i class="fa fa-btn fa-unlock"></i>Admin
#endrole
<a href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endif
</ul>

Multi-auth not working 5.4

I have 2 users which is seller and user. Login function for both is fine but when I login to seller there is no logout button.
Route:
Route::post('/logout', 'Auth\PsController#logout');
psblade:
<ul class="nav navbar-nav navbar-right">
<!-- Authentication Links -->
#if (Auth::guest())
<li>Loginnn</li>
<li>Registerr</li>
#else
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
<a href="{{ route('/logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
Logout
</a>
<form id="logout-form" action="{{ route('/logout') }}" method="POST" style="display: none;">
{{ csrf_field() }}
</form>
</li>
</ul>
</li>
#endif

Categories