当前位置: 首页>>代码示例>>PHP>>正文


PHP Router::bind方法代码示例

本文整理汇总了PHP中Illuminate\Routing\Router::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Router::bind方法的具体用法?PHP Router::bind怎么用?PHP Router::bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Routing\Router的用法示例。


在下文中一共展示了Router::bind方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     // $router->model('amministratori', \App\Amministratore::class);                         /* versione semplice */
     $router->bind('amministratori', function ($id) {
         /*versione con opzioni specifiche*/
         return \App\Amministratore::where('id', $id)->FirstOrFail();
     });
     $router->bind('utenti', function ($id) {
         /*versione con opzioni specifiche*/
         return \App\Utente::where('id', $id)->FirstOrFail();
     });
     $router->bind('aziende', function ($id) {
         /*versione con opzioni specifiche*/
         return \App\Azienda::where('id', $id)->FirstOrFail();
     });
     $router->bind('problemi', function ($id) {
         /*versione con opzioni specifiche*/
         return \App\Problema::where('id', $id)->FirstOrFail();
     });
     $router->bind('preventivi', function ($id) {
         /*versione con opzioni specifiche*/
         return \App\Preventivo::where('id', $id)->FirstOrFail();
     });
     parent::boot($router);
 }
开发者ID:MP86,项目名称:App,代码行数:31,代码来源:RouteServiceProvider.php

示例2: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     // Sets up our routing tokens.
     $router->pattern('board', Board::URI_PATTERN);
     $router->pattern('id', '[1-9]\\d*');
     $router->model('ban', '\\App\\Ban');
     $router->model('board', '\\App\\Board');
     $router->model('post', '\\App\\Post');
     $router->model('report', '\\App\\Report');
     $router->model('role', '\\App\\Role');
     $router->bind('user', function ($value, $route) {
         if (is_numeric($value)) {
             return \App\User::find($value);
         } else {
             if (preg_match('/^[a-z0-9]{1,64}\\.(?P<id>\\d+)$/i', $value, $matches)) {
                 return \App\User::find($matches['id']);
             }
         }
     });
     $router->bind('role', function ($value, $route) {
         if (is_numeric($value)) {
             return \App\Role::find($value);
         } else {
             if (preg_match('/^[a-z0-9]{1,64}\\.(?P<id>\\d+)$/i', $value, $matches)) {
                 return \App\Role::find($matches['id']);
             }
         }
     });
     $router->bind('post_id', function ($value, $route) {
         $board = $route->getParameter('board');
         if (is_numeric($value) && $board instanceof Board) {
             return $board->getThreadByBoardId($value);
         }
     });
     // Binds a matched instance of a {board} as a singleton instance.
     $router->matched(function ($route, $request) {
         // Binds the board to the application if it exists.
         $board = $route->getParameter('board');
         if ($board instanceof Board && $board->exists) {
             $board->applicationSingleton = true;
             //$this->app->instance("\App\Board", $board);
             $this->app->singleton("\\App\\Board", function ($app) use($board) {
                 return $board->load(['assets', 'settings']);
             });
         }
         // Binds the post to the application if it exists.
         $post = $route->getParameter('post_id');
         if ($post instanceof Post && $post->exists) {
             $route->setParameter('post', $post);
             //$this->app->instance("\App\Post", $post);
             $this->app->singleton("\\App\\Post", function ($app) use($post) {
                 return $post;
             });
         }
     });
     parent::boot($router);
 }
开发者ID:JEWSbreaking8chan,项目名称:infinity-next,代码行数:63,代码来源:RouteServiceProvider.php

示例3: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('articles', function ($id) {
         return Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($tags) {
         return Tag::where('name', $tags)->first();
     });
     parent::boot($router);
 }
开发者ID:rkang30,项目名称:newdev_L5.1,代码行数:16,代码来源:RouteServiceProvider.php

示例4: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     // $router->model('articles', 'App\Article');
     $router->bind('articles', function ($id) {
         return \App\Article::published()->findOrFail($id);
     });
     $router->bind('tags', function ($name) {
         return \App\Tag::where('name', $name)->firstOrFail();
     });
     parent::boot($router);
 }
开发者ID:nikolaynizruhin,项目名称:Laravel5Blog,代码行数:17,代码来源:RouteServiceProvider.php

示例5: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('integrations', function ($id) use($router) {
         $user = \Auth::user();
         return Integration::whereUserId($user->id)->whereId($id)->firstOrFail();
     });
     $router->bind('monitors', function ($uuid) {
         return Monitor::where('uuid', $uuid)->firstOrFail();
     });
     parent::boot($router);
 }
开发者ID:hmazter,项目名称:cron-monitor,代码行数:17,代码来源:RouteServiceProvider.php

示例6: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->model('effects', 'App\\Effect');
     $router->model('potion-effects', 'App\\PotionEffect');
     $router->bind('potions', function ($id) {
         return Potion::with('ingredients')->where('id', $id)->first();
     });
     $router->bind('ingredients', function ($id) {
         return Ingredient::with('effects')->where('id', $id)->first();
     });
     parent::boot($router);
 }
开发者ID:rdok,项目名称:oblivion-pm,代码行数:18,代码来源:RouteServiceProvider.php

示例7: map

 /**
  * Define the routes for the application.
  *
  * @param  \Illuminate\Routing\Router $router
  * @return void
  */
 public function map(Router $router)
 {
     $router->group(['namespace' => $this->namespace], function ($router) {
         require app_path('Http/routes.php');
     });
     $router->bind('post', function ($value) {
         return Post::where(['slug' => $value])->first();
     });
     $router->bind('activepost', function ($value) {
         return Post::where(['slug' => $value, 'active' => 1])->first();
     });
 }
开发者ID:bastienbot,项目名称:wordpresskilled.me,代码行数:18,代码来源:RouteServiceProvider.php

示例8: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('messages', function ($id) {
         return \App\Messages::findOrFail($id);
     });
     $router->bind('tweets', function ($id) {
         return \App\Tweet::findOrFail($id);
     });
     $router->bind('users', function ($id) {
         return \App\User::findOrFail($id);
     });
     parent::boot($router);
 }
开发者ID:jasonraimondi,项目名称:twitterclone,代码行数:19,代码来源:RouteServiceProvider.php

示例9: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     // Route Bindings
     $router->bind('categories', function ($value) {
         return Category::whereSlug($value)->first();
     });
     $router->bind('posts', function ($value) {
         return Post::whereSlug($value)->first();
     });
     $router->bind('author', function ($value) {
         return User::whereName($value)->first();
     });
     parent::boot($router);
 }
开发者ID:shempignon,项目名称:laravel-5-blog-mvc,代码行数:20,代码来源:RouteServiceProvider.php

示例10: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('facility', function ($slug) {
         return \App\Facility::where('slug', $slug)->first();
     });
     $router->bind('type', function ($slug) {
         return \App\RoomType::where('slug', $slug)->first();
     });
     $router->bind('room', function ($room_no) {
         return \App\Room::where('room_no', $room_no)->first();
     });
     $router->model('reservation', 'App\\Reservation');
     parent::boot($router);
 }
开发者ID:nugi,项目名称:simpleCRUD,代码行数:20,代码来源:RouteServiceProvider.php

示例11: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('posts', function ($slug) {
         return Post::whereSlug($slug)->first();
     });
     parent::boot($router);
 }
开发者ID:Hub-IT,项目名称:gazette,代码行数:13,代码来源:RouteServiceProvider.php

示例12: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('article', function ($slug) {
         return Article::where('slug', $slug)->firstOrFail();
     });
     parent::boot($router);
 }
开发者ID:Ravend6,项目名称:laravel_base_v5.2,代码行数:13,代码来源:RouteServiceProvider.php

示例13: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  *
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('pages', function ($id) {
         return Page::find($id);
     });
     parent::boot($router);
 }
开发者ID:philsown,项目名称:seia-laravel-core,代码行数:14,代码来源:RouteServiceProvider.php

示例14: boot

 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('posts', function ($value) {
         return Post::findBySlugOrIdOrFail($value);
     });
     parent::boot($router);
 }
开发者ID:spitzgoby,项目名称:spitzgoby,代码行数:13,代码来源:RouteServiceProvider.php

示例15: boot

 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('article', function ($id) {
         return \App\Article::where('slug', $id)->first();
     });
     parent::boot($router);
 }
开发者ID:belhard-user,项目名称:group2,代码行数:12,代码来源:ModelProviders.php


注:本文中的Illuminate\Routing\Router::bind方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。