Ejemplo: URL dinámica laravel
public function showBySlug($slug) {
$post = Post::where('slug','=',$slug)->first();
// would use app/posts/show.blade.php
return View::make('posts.show')->with(array(
'post' => $post,
));
}
Then you can route it like this:
Route::get('post/{slug}', '[email protected]')
->where('slug', '[-_A-Za-z]+');`
...which has the added bonus of allowing you an easy way to link straight to the slug routes on an index page, for example:
@foreach ($posts as $post)
<h2>{{ HTML::link(
action('[email protected]', array($post->slug)),
$post->title
)}}</h2>
@endforeach
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)