Search code examples
phplaravellaravelcollective

Only show button to loged-in user in Laravel-Collective


How to insert @if statement for only show the "red color delete action button" to loged-in user in below code?

enter image description here

{!! Form::open(['route' => ['jobs.destroy', $job->id], 'method' => 'delete']) !!}
  <div class='btn-group'>
    <a href="{!! route('jobs.show', [$job->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
    <a href="{!! route('jobs.edit', [$job->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
                {!! Form::button('<i class="glyphicon glyphicon-stop"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure to Stop?')"]) !!}
  </div>
{!! Form::close() !!}

thank you in advenced.


Solution

  • You can use Auth::check() like this :

    {!! Form::open(['route' => ['jobs.destroy', $job->id], 'method' => 'delete']) !!}
      <div class='btn-group'>
        <a href="{!! route('jobs.show', [$job->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
        <a href="{!! route('jobs.edit', [$job->id]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
        @if (Auth::check())
          {!! Form::button('<i class="glyphicon glyphicon-stop"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure to Stop?')"]) !!}
        @endif
        </div>
    {!! Form::close() !!}