Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Route
- Route::model ('page', 'Page'); // The {page} variable is an instance of the Page model
- Route::get ('/p/{page}', 'PageController@show'); // The show method in the PageController controller will handle this URL with {page} as a parameter
- # Model
- class Page extends Eloquent
- {
- protected $table = 'page'; // Use the page table in the database
- public function author ()
- {
- return $this->belongsTo ('Author'); // This Page belongs to an Author
- }
- }
- class Author extends Eloquent
- {
- protected $table = 'author'; // Use the author table in the database
- }
- # Controller
- class PageController extends BaseController
- {
- public function show ($page)
- {
- return View::make ('page', compact ('page')); // Make the view page.blade.php and pass the $page variable (which is an instance of the Page model) to it
- }
- }
- # View (filename: page.blade.php)
- <!DOCTYPE html>
- <html>
- <head>
- <title>{{ $page->title }}</title>
- </head>
- <body>
- <h1>{{ $page->title }}</title>
- <p id="author">Author: {{ $page->author->name }}</p>
- <div id="content">
- {{ $page->content }}
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment