Support the ongoing development of Laravel.io →
Security Cache Views
Last updated 1 year ago.
0

Route binding. http://laravel.com/docs/routing#route-model-binding

Routes.php

Route::get('/view/{post_slug}', ['uses' => 'PostController@view']);

Route::bind('post_slug', function($value, $route)
{
    // Return a model based on the value in the route URI
    return Post::where('slug', $value)->firstOrFail();
});

PostController.php

function view(Post $post)
{
    // $post is an instance of Post that is returned from the Route::bind() method.
    return View::make('posts.view', ['post' => $post]);
}
Last updated 1 year ago.
0

I get this error

No query results for model [User]
Last updated 1 year ago.
0
// Routes
Route::get('post/{slug}, 'PostsController@show');

// PostsController
public function show($slug)
{
    $post = Post::whereSlug($slug)->first();

    return View::make('posts.show', ['post' => $post]);
}
Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

shiva shiva Joined 24 Jul 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.