Call to undefined method Illuminate\Session\Store::user() (View: C:\xampp\htdocs\vms_ut\resources\views\layouts\navbar.blade.php) (View: C:\xampp\htdocs\vms_ut\resources\views\layouts\navbar.blade.php)
View
<ul class="navbar-nav">
<li>Home</li>   
#if (Session::user()->level == 'Admin')
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">
Master <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>Data</li>
<li>Warehouse</li>
</ul>
</li>
#else (Session::user()->level == 'Penyedia')
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button">
Master <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>Data</li>
</ul>
</li>
#endif
</ul>
view
enter image description here
please help me
You mean Auth instead of Session?
Change this line:
#if (Session::user()->level == 'Admin')
To this line
#if (Auth::user()->level == 'Admin')
You can use session facade as such:
use Illuminate\Support\Facades\Session ;
Related
Am using same navbar for shop products and shop product. #if statement isn't working. Here is navbar:
<ul class="navbar-nav ml-auto">
<li class="nav-item">
#if (\Request::path('/shop'))
<a class="nav-link js-scroll-trigger" href="#page-top">Shop</a>
#elseif (\Request::path('/product'))
<a class="nav-link js-scroll-trigger" href="/shop">Shop</a>
#endif
</li>
<li class="nav-item">
<a class="nav-link js-scroll-trigger" href="#contact">Contact</a>
</li>
</ul>
Here is routes:
Route::view('/product', 'shop.product');
Route::get('/shop', 'ShopController#index')->name('shop.index');
You can use request()->is() function of request. as below:
#if (request()->is('shop'))
<a class="nav-link js-scroll-trigger" href="#page-top">Shop</a>
#elseif (request()->is('product'))
<a class="nav-link js-scroll-trigger" href="/shop">Shop</a>
#endif
I want to make my index page with both guest and auth functions.
When guests visit, they could try logging in; And after login, it will show the user's info such as username.
Route routes/web.php:
Route::get('vendor', function () {
return view('vendor.home');
})->name('vendor')->middleware('web');
in blade template i use Auth::check() to authentication but failed.if i use middleware(['web','auth:vendor']) if guest will redirect to login page
#if(Auth::guest())
<li> <strong><i class="fa fa-user"></i> Login </strong> </li>
<li> <strong>Register</strong> </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>
Log Out
</li>
</ul>
</li>
#endif
{{ dd(Auth::check()) }}
Every time I logged in successfully, it will still show login button instead of user name button, after I REFRESH the index page.
this result
try replace Auth:: with \Auth:: or auth()
#if(\Auth::guest())
<li> <strong><i class="fa fa-user"></i> Login </strong> </li>
<li> <strong>Register</strong> </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>
Log Out
</li>
</ul>
</li>
#endif
{{ dd(\Auth::user()) }}
This my answer
#if(Auth::guard('vendor')->check())
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
{{ Auth::guard('vendor')->user()->name }} <span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li>
Dashboard
</li>
<li>
<a href="{{ route('vendor.logout') }}" >Log Out</a>
</li>
</ul>
</li>
#else
<li> <strong><i class="fa fa-lock"></i> Login </strong> </li>
<li> <strong>Register</strong> </li>
#endif
I am having trouble to adding class "menu-open" and "active" if I use a Multi-level menu.
I succeeded in adding active class in single menu.
Single Menu
<li class="nav-item">
<a href="{{ route('listTemuan') }}" class="nav-link {{ Route::currentRouteNamed('listTemuan') ? 'active' : '' }}">
<i class="fa fa-table nav-icon"></i>
<p>
List Temuan
</p>
</a>
</li>
I don't understand how to make it in Multi-level menu.
This is for my Multi-level menu:
<li class="nav-item has-treeview"> //I want to add class menu-open in here
<a href="#" class="nav-link"> //I want to add class active in here
<i class="fa fa-gear nav-icon"></i>
<p>
Setting
<i class="right fa fa-angle-left"></i>
</p>
</a>
<ul class="nav nav-treeview">
<li class="nav-item">
<a href="{{ route('UserPekerja') }}" class="nav-link {{ Route::currentRouteNamed('UserPekerja') ? 'active' : '' }}">
<i class="fa fa-circle-o nav-icon"></i>
<p>User Pekerja</p>
</a>
</li>
</ul>
</li>
Use your route name to accomplish it like below code
#if(\Request::route()->getName() == 'route name')
class="nav-item has-treeview open"
#else class="nav-item has-treeview"
#endif
use same segment with appropriate checking
#if(\Request::route()->getName() == 'expected route name')
class="nav-link active"
#else class="nav-link"
#endif
I have a proyect with symfony 2.8. When I add a dropdown on mi navbar in twig, is added correctly. But when I click on it the dropdown not drop... The url change adding the # of href, but this not dropdwon.
My code is:
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button"
aria-expanded="false"> <img src="" height="40" width="40" class="profile-photo img-circle">
{{ app.user.username }} <span class="caret"></span></a>
<ul class="dropdown-menu" role="menu">
<li>
Edit
</li>
<li class="divider"></li>
<li>
Logout
</li>
</ul>
</li>
</ul>
How can implement this on twig to work??
Thanks!
i using laravel 5.2, I want to change the menu login to logout when user login but
but the result is as shown belowenter image description here
this is my code
<div id="headerweb">
<div class="wrapper">
<img src="<?=asset('public/images/mainlogo.png')?>" alt=""/>
<div class="mainmenu">
<ul>
<li>CARA KERJA </li>
<li>ORDER TES LAB </li>
<li>HASIL LAB ONLINE </li>
<li>LOKASI LAB </li>
<li>BLOG </li>
#if (Auth::guest())
<li>LOGIN </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><i class="fa fa-btn fa-sign-out"></i>Logout</li>
</ul>
#endif
</ul>
</div>
</div>
</div><!-- endheaderweb -->
any one help me??
Please, ensure that you've closed the #if statement and the #headerweb div.
<div id="headerweb">
<div class="wrapper">
<img src="<?=asset('public/images/mainlogo.png')?>" alt=""/>
<div class="mainmenu">
<ul>
<li>CARA KERJA</li>
<li>ORDER TES LAB</li>
<li>HASIL LAB ONLINE</li>
<li>LOKASI LAB</li>
<li>BLOG</li>
#if (Auth::guest())
<li>LOGIN</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><i class="fa fa-btn fa-sign-out"></i>Logout</li>
</ul>
#endif
</ul>
</div>
</div>
</div>
Also, please move your welcome route from the routes.php file to inside the web middleware and that should change the login to logout and display the user name when logged in.
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
});