Laravel Version: 7.6.2
Laratrust Version: 5.2.8
I have a Laravel 7.6 project and I use Laratrust for user roles and permissions. In my project, When i renamed permission name for example from management.dashboard.index to management-dashboard-index, but my web application not be loaded (It does not display an error).
Although I have cleared all the caches with php artisan cache:clear.
aside menu view :
#if ($user->can('management-dashboard-index'))
<li class="kt-menu__section ">
<h4 class="kt-menu__section-text">مدیریت</h4>
<i class="kt-menu__section-icon flaticon-more-v2"></i>
</li>
<li class="kt-menu__item kt-menu__item--submenu {!! (Request::is('management/panel/users*')) || (Request::is('management/panel/roles*')) || (Request::is('management/panel/permissions*')) ? 'kt-menu__item--open kt-menu__item--here' : '' !!}" aria-haspopup="true" data-ktmenu-submenu-toggle="hover">
<a href="javascript:;" class="kt-menu__link kt-menu__toggle">
<span class="kt-menu__link-icon">
<i class="la la-users"></i>
</span>
<span class="kt-menu__link-text">کاربران</span>
<i class="kt-menu__ver-arrow la la-angle-right"></i>
</a>
<div class="kt-menu__submenu ">
<span class="kt-menu__arrow"></span>
<ul class="kt-menu__subnav">
#if ($user->can('management.users.index'))
<li class="kt-menu__item {!! Request::is('management/panel/users*') ? 'kt-menu__item--active' : '' !!}" aria-haspopup="true">
<a href="{{ route('management.users.index') }}" class="kt-menu__link ">
<i class="kt-menu__link-bullet kt-menu__link-bullet--dot">
<span></span>
</i>
<span class="kt-menu__link-text">لیست کاربران</span>
</a>
</li>
#endif
#if ($user->can('management.permissions.index'))
<li class="kt-menu__item {!! Request::is('management/panel/permissions*') ? 'kt-menu__item--active' : '' !!}" aria-haspopup="true">
<a href="{{ route('management.permissions.index') }}" class="kt-menu__link ">
<i class="kt-menu__link-bullet kt-menu__link-bullet--dot">
<span></span>
</i>
<span class="kt-menu__link-text">پرمیشن ها</span>
</a>
</li>
#endif
#if ($user->can('management.roles.index'))
<li class="kt-menu__item {!! Request::is('management/panel/roles*') ? 'kt-menu__item--active' : '' !!}" aria-haspopup="true">
<a href="{{ route('management.roles.index') }}" class="kt-menu__link ">
<i class="kt-menu__link-bullet kt-menu__link-bullet--dot">
<span></span>
</i>
<span class="kt-menu__link-text">سطوح دسترسی</span>
</a>
</li>
#endif
</ul>
</div>
</li>
#endif
i get this message شما سطح دسترسی لازم را برای دیدن این صفحه ندارید
check the output of this part of your code $user->can('management-dashboard-index')
I think the answer will find if continue digging here.
start by seeing the result of {{ $user->can('management-dashboard-index') }}
Related
I am a newbie to Laravel. The logout option is not working for me in Laravel. It shows Login and Home Menus. After I logged in it shows the username with a down arrow, but the dropdown is not working. What could be the issue?
This is my app.blade.php
<nav class="navbar navbar-expand-md navbar-light bg-white shadow-sm">
<div class="container">
<a class="navbar-brand" href="{{ url('/') }}">
{{ config('app.name', 'Laravel') }}
</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="{{ __('Toggle navigation') }}">
<span class="navbar-toggler-icon"></span>
</button>
<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="{{ route('login') }}">{{ __('Login') }}</a>
</li>
#if (Route::has('register'))
<li class="nav-item">
<a class="nav-link" href="{{ route('register') }}">{{ __('Register') }}</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>
{{ Auth::user()->name }}
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<a class="dropdown-item" href="{{route('admin.users.index')}}">
User Management
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" class="d-none">
{{ csrf_field() }}
</form>
</div>
</li>
#endguest
</ul>
</div>
</div>
</nav>
How can I set active selected tab and and also open the sub tab if the page I'm on is a sub page on my sidebar? For example if I open Contractor Association page, the Users tab should expand the highlight Contractor Association tab. Right now every time I open a new page the sidebar is will reset back
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link {{ (request()->is('home')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.home') }}">
<i class="ni ni-tv-2"></i> {{ __('Dashboard') }}
</a>
</li>
<li class="nav-item">
<a class="nav-link {{ (strpos(Route::currentRouteName(), 'dev-admin.home') == 0) ? 'text-primary' : '' }}"
href="#users" data-toggle="collapse" role="button" aria-expanded="true" aria-controls="users">
<i class="fa fa-users"></i>
<span class="nav-link-text">{{ __('Users') }}</span>
</a>
<div class="collapse {{ (request()->is('dev-admin/developer-admins*') ? 'show' : '' }}"
id="users">
<ul class="nav nav-sm flex-column">
<li class="nav-item">
<a class="nav-link {{ (request()->is('developer-admins')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.developer-admins.index') }}">
{{ __('Admins') }}
</a>
<a class="nav-link {{ (request()->is('dev-admin/defect-types*')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.clerk-of-works.index') }}">
{{ __('Clerks of Work') }}
</a>
<a class="nav-link {{ (request()->is('developer-admins')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.developer-contractor-associations.index') }}">
{{ __('Contractor Association') }}
</a>
</li>
</ul>
</div>
</li>
</ul>
you can write the code like in side bar all the section
<li class="#if(Route::is('developer-admins')) {{ 'active' }} #endif"
<a href="{{ route('dev-admin.developer-admins.index') }}">
{{ __('Admins') }}
</a></li>
and also you can use like
<li class="{{ set_active(['login*']) }}">
Login
</li>
<li class="{{ set_active(['register*']) }}">
Signup
</li>
I am using bellow code for many project which is used into production ready web app and api.
Add bellow line into html class attributes for highlighting active route.
{{ request()->is('dashboard/report') ? 'active' : '' }}
This is really handy for active class.
So I fix it and also show/open tab for selected page by doing something like this, it appears the url I gave is incomplete, thanks everyone for the suggestion..
<div class="collapse {{ (request()->is('dev-admin/developer-admins*') || request()->is('dev-admin/clerks-of-works*') || request()->is('dev-admin/developer-contractor-associations*')) ? 'show' : '' }}"
id="users">
<ul class="nav nav-sm flex-column">
<li class="nav-item">
<a class="nav-link {{ (request()->is('dev-admin/developer-admins*')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.developer-admins.index') }}">
{{ __('Admins') }}
</a>
<a class="nav-link {{ (request()->is('dev-admin/clerks-of-works*')) ? 'text-primary' : '' }}"
href="{{ route('dev-admin.clerk-of-works.index') }}">
{{ __('Clerks of Work') }}
</a>
</li>
</ul>
</div>
I need check My Laravel app with current logging user id(Auth) and user_id in task table and run if else command. I need show task_name in task table with different user_id. among them if user_id is equal to current I need show following items on My blade file.
#foreach ($project->tasks as $task)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<i class="glyphicon glyphicon-plus"></i>
</div>
<h4><i class="fa fa-check-square-o"></i> <span>{{ $task->task_name }}
</span></h4>
</div>
</li>
</ul>
<hr>
#endforeach
and if task user_id is not equels to Auth id should display following items
#foreach ($project->tasks as $task)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<i class="glyphicon glyphicon-plus"></i>
<i class="glyphicon glyphicon-pencil"></i>
<i class="glyphicon glyphicon-trash"></i>
</div>
<h4><i class="fa fa-check-square-o"></i> <span>{{ $task->task_name }}
</span></h4>
</div>
</li>
</ul>
<hr>
#endforeach
how can do this?
My task table as this
id task_name user_id
1 dfr 1
2 bgh 2
3 hyg 1
4 hyu 4
You can use the auth() helper. These helpers are available on both blade files and Controllers.
#foreach ($project->tasks as $task)
#if(auth()->user()->id == $task->user_id)
// do something
#else
// do something
#endif
#endforeach
Then that's it.
You need to compare auth user with your task user variable in if condition and then display the data like below:
#if(auth()->user()->id == $task->user_id)
#foreach ($project->tasks as $task)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i>
</a>
</div>
<h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}
</a>
</span></h4>
</div>
</li>
</ul>
<hr>
#endforeach
#else
#foreach ($project->tasks as $task)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i>
</a>
<i class="glyphicon glyphicon-pencil"></i>
<a href="" class="editInline"><i class="glyphicon glyphicon-trash">
</i></a>
</div>
<h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}
</a>
</span></h4>
</div>
</li>
</ul>
<hr>
#endforeach
#endif
You can also #if condition within #foreach to just use it once if both #foreach are same and can update your code like below:
#foreach ($project->tasks as $task)
#if(auth()->user()->id == $task->user_id)
<ul>
<li>
<div>
<div class="pull-right icons-align">
<a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i>
</a>
</div>
<h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}
</a>
</span></h4>
</div>
</li>
</ul>
<hr>
#else
<ul>
<li>
<div>
<div class="pull-right icons-align">
<a href="{{url('projects/'.$project->id.'/task/'.$task->id.'/subtask')}}" class="editInline"><i class="glyphicon glyphicon-plus"></i>
</a>
<i class="glyphicon glyphicon-pencil"></i>
<a href="" class="editInline"><i class="glyphicon glyphicon-trash">
</i></a>
</div>
<h4><i class="fa fa-check-square-o"></i> <span><a href="/projects/{{$project->id}}/tasks/{{ $task->id }}">{{ $task->task_name }}
</a>
</span></h4>
</div>
</li>
</ul>
<hr>
#endif
#endforeach
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.
If I was looping through a number of results in a foreach and the list was as such -
-item 1
delete
-item 2
delete
-item 3
delete
-item 4
delete
If I want to delete the item 3 record how can I find the correct id for that iteration for my query. Normally I would use a get request but that wouldn't work in this case.
Thanks
#foreach ($statuses as $status)
<div class="media post-margin">
<a class="pull-left" href="{{ route('profile.index', ['username' => $status->user->username]) }}">
<img class="media-object" alt="{{ $status->user->getNameOrUsername() }}" src="{{ $status->user->getAvatarUrl() }}">
</a>
<div class="media-body">
<h4 class="media-heading">{{ $status->user->getNameOrUsername() }}</h4>
<span>{{ $status->created_at->diffForHumans() }}</span>
</div>
<p>{{ $status->body }}</p>
<hr>
<ul class="list-inline">
<li><i class="fa fa-thumbs-up fa-liked"></i> {{ $status->likes->count() }} {{ str_plural('like', $status->likes->count()) }}</li>
<li><i class="fa fa-comments-o"></i> Comment</li>
<li><i class="fa fa-retweet"></i> Share</li>
#if ($status->user->id === Auth::user()->id)
<li id="remove"><a href="#"><i class="fa fa-times"></i> Delete</li>
#endif
</ul>
<hr>
</div>
#endforeach
You just need to pass the record id to be deleted.
#foreach ($statuses as $status)
<div class="media post-margin">
<a class="pull-left" href="{{ route('profile.index', ['username' => $status->user->username]) }}">
<img class="media-object" alt="{{ $status->user->getNameOrUsername() }}" src="{{ $status->user->getAvatarUrl() }}">
</a>
<div class="media-body">
<h4 class="media-heading">{{ $status->user->getNameOrUsername() }}</h4>
<span>{{ $status->created_at->diffForHumans() }}</span>
</div>
<p>{{ $status->body }}</p>
<hr>
<ul class="list-inline">
<li><i class="fa fa-thumbs-up fa-liked"></i> {{ $status->likes->count() }} {{ str_plural('like', $status->likes->count()) }}</li>
<li><i class="fa fa-comments-o"></i> Comment</li>
<li><i class="fa fa-retweet"></i> Share</li>
#if ($status->user->id === Auth::user()->id)
<li id="remove"><a href="{{route('status.delete',['statusId',$status -> id])}}"><i class="fa fa-times"></i> Delete</li>
#endif
</ul>
<hr>
</div>
#endforeach
Routes
route::get('/delete/{$id}',['as' =>'status.delete' , 'uses' => 'YourController#delete']);
Controller
public function delete($id){
Model::destroy($id); //
}
Hope this help.