This is the view of posts on a blog to create, edit, view and delete. I want to restrict the create and delete button so that a user with a certain id can be the only one to see and use these buttons.
Here I put the code of the view:
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">
Lista de Entradas
<a href="{{ route('posts.create') }}"
class="btn btn-sm btn-primary pull-right">Crear</a>
</div>
<div class="panel-body">
<table class="table table-striped table-hover">
<thead>
<tr>
<th width="10px">ID</th>
<th>NOMBRE</th>
<th colspan="3"> </th>
</tr>
</thead>
<tbody>
@foreach($posts as $post)
<tr>
<td>{{ $post->id }}</td>
<td>{{ $post->name }}</td>
<td width="10px">
<a href="{{ route('posts.show', $post->id) }}" class="btn btn-sm btn-default">ver
</a>
</td>
<td width="10px">
<a href="{{ route('posts.edit', $post->id) }}" class="btn btn-sm btn-default">editar
</a>
</td>
<td width="10px">
{!! Form::open(['route' => ['posts.destroy',
$post->id], 'method' => 'DELETE']) !!}
<button class="btn btn-sm btn-danger">
Eliminar
</button>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>
{{ $posts->render() }}
</div>
</div>
</div>
</div>
</div>
This is what the user should see with a certain id that allows him to see the buttons:
And this is what the rest of the users should see:
That is, basically it is to prevent users from creating or deleting except for a specific user with a certain id.
Edit1: I was able to fix it by adding this conditional in the view:
@if(Auth::user()->id == 29)
<a href="{{ route('posts.create') }}"
class="glyphicon glyphicon-plus btn
btn-sm btn-primary pull-right"> Crear</a>
@endif
In this way only the user with that specific id can create. The same case would be to eliminate.