當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。