Is it right approach to write Laravel PHP code to give a role to hr to view certain column? Because after hosting the website stops automatically and start automatically. Code is working fine..
I am new to PHP, I have no idea if i am going wrong in this code can anyone help me out yrr...
<table >
<thead>
<tr>
@role('company')
<th>{{__('Employee Name')}}</th>
@endrole
@role('hr')
<th>{{__('Employee Name')}}</th>
@endrole
<th>{{__('Designation')}}</th>
<th>{{__('Promotion Title')}}</th>
<th>{{__('Promotion Date')}}</th>
<th>{{__('Description')}}</th>
@if(Gate::check('Edit Promotion') || Gate::check('Delete Promotion'))
<th width="200px">{{__('Action')}}</th>
@endif
</tr>
</thead>
<tbody >
@foreach ($promotions as $promotion)
<tr>
@role('company')
<td>{{ !empty($promotion->employee())?$promotion->employee()->name:'' }}</td>
@endrole
@role('hr')
<td>{{ !empty($promotion->employee())?$promotion->employee()->name:'' }}</td>
@endrole
<td>{{ !empty($promotion->designation())?$promotion->designation()->name:'' }}</td>
<td>{{ $promotion->promotion_title }}</td>
<td>{{ \Auth::user()->dateFormat($promotion->promotion_date) }}</td>
<td>{{ $promotion->description }}</td>
@if(Gate::check('Edit Promotion') || Gate::check('Delete Promotion'))
<td>
@can('Edit Promotion')
<a href="#" data-url="{{ URL::to('promotion/'.$promotion->id.'/edit') }}" data-size="lg" data-ajax-popup="true" data-title="{{__('Edit Promotion')}}" data-toggle="tooltip" data-original-title="{{__('Edit')}}"><i ></i></a>
@endcan
@can('Delete Promotion')
<a href="#" data-toggle="tooltip" data-original-title="{{__('Delete')}}" data-confirm="{{__('Are You Sure?').'|'.__('This action can not be undone. Do you want to continue?')}}" data-confirm-yes="document.getElementById('delete-form-{{$promotion->id}}').submit();"><i ></i></a>
{!! Form::open(['method' => 'DELETE', 'route' => ['promotion.destroy', $promotion->id],'id'=>'delete-form-'.$promotion->id]) !!}
{!! Form::close() !!}
@endif
</td>
@endif
</tr>
@endforeach
</tbody>
</table>
CodePudding user response:
You can find what you are asking in the documentation here (version select on the left):
https://spatie.be/docs/laravel-permission/v5/basic-usage/blade-directives
@role('hr')
I am from hr!
@else
I am not from hr...
@endrole
It further reads @hasrole('hr')
is an alias of @role('hr')
, so no worries there.
Similarly, the same goes for permissions:
@can('edit articles')
//
@endcan
For more information, see link mentioned above.