Advertisement
Guest User

Untitled

a guest
Jul 7th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.15 KB | None | 0 0
  1. //routes.php
  2. Route::resource('posts', 'PostsController');
  3.  
  4. //controller
  5.  
  6. public function show($id)
  7. {
  8. $post = Post::findOrFail($id);
  9.  
  10. return view('posts.show', compact('post'));
  11. }
  12.  
  13. public function destroy($id)
  14. {
  15. Post::delete($id);
  16.  
  17. return redirect('posts');
  18. }
  19.  
  20. //view/posts/index.blade.php
  21.  
  22. @extends('app')
  23.  
  24. @section('content')
  25. {!! link_to('posts/create', 'Add Post', ['class' => 'btn btn-primary']) !!}
  26.  
  27. @if ($posts)
  28. <hr/>
  29. <table class="table table-bordered table-striped table-hover">
  30. <tr>
  31. <th>Title</th>
  32. <th>Description</th>
  33. <th>Published on</th>
  34. <th>Action</th>
  35. </tr>
  36. @foreach ($posts as $post)
  37. <tr>
  38. <td>{!! link_to_action('PostsController@show', $post->title, $parameters = array($post->id)) !!}</td>
  39. <td>{!! $post->description !!}</td>
  40. <td>{!! $post->published_at !!}</td>
  41. <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>
  42. </tr>
  43. @endforeach
  44. </table>
  45. @endif
  46. @stop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement