Skip to content

Instantly share code, notes, and snippets.

@aavrug
Created June 10, 2015 06:58
Show Gist options
  • Save aavrug/516ba2768bb8eb32f9dc to your computer and use it in GitHub Desktop.
Save aavrug/516ba2768bb8eb32f9dc to your computer and use it in GitHub Desktop.
//routes.php
Route::resource('posts', 'PostsController');
//controller
public function show($id)
{
$post = Post::findOrFail($id);
return view('posts.show', compact('post'));
}
public function destroy($id)
{
Post::delete($id);
return redirect('posts');
}
//view/posts/index.blade.php
@extends('app')
@section('content')
{!! link_to('posts/create', 'Add Post', ['class' => 'btn btn-primary']) !!}
@if ($posts)
<hr/>
<table class="table table-bordered table-striped table-hover">
<tr>
<th>Title</th>
<th>Description</th>
<th>Published on</th>
<th>Action</th>
</tr>
@foreach ($posts as $post)
<tr>
<td>{!! link_to_action('PostsController@show', $post->title, $parameters = array($post->id)) !!}</td>
<td>{!! $post->description !!}</td>
<td>{!! $post->published_at !!}</td>
<td>{!! link_to_action('PostsController@edit', 'Edit Post', $parameters = array($post->id), $attributes = ['class' => 'btn btn-warning']) !!} {!! link_to_action('posts.destroy', 'Delete', $parameters = array($post->id), $attributes = ['class' => 'btn btn-danger']) !!}</td>
</tr>
@endforeach
</table>
@endif
@stop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment