namespace App\Providers;

class RouteServiceProvider extends ServiceProvider
{

    public function boot(Router $router)
    {

        parent::boot($router);
         
        //在这里添加绑定
        $route->model('articles', 'App\Article');   
   //或者
$route->bind('articles', function($id){
//do somthing...
});
}

参数articles用php artisan route:list 可以查到 articles{articles},这样在控制器中直接得到的是对应的article了,不用自己去通过ID查询了。

posted on 2015-09-14 01:25  jzfan  阅读(288)  评论(0编辑  收藏  举报