Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement