bind() public method

Add a new route parameter binder.
public bind ( string $key, string | callable $binder ) : void
$key string
$binder string | callable
return void
Example #1
0
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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();
     });
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
Example #10
0
 /**
  * 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);
 }
Example #11
0
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
 /**
  * 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);
 }
Example #15
0
 /**
  * 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);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('attendees', function ($id) {
         return \App\Attendee::where('id', $id)->firstOrFail();
     });
     parent::boot($router);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->bind('username', function ($username) {
         return User::whereUsername($username)->first();
     });
     parent::boot($router);
 }
 /**
  * Define the routes for the application.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function map(Router $router)
 {
     $router->when('admin/contacts*', 'AdminRole');
     $router->bind('contact', function ($value) {
         return Contact::where('id', $value)->first();
     });
     /**
      * API routes
      */
     $router->group(['namespace' => $this->namespace, 'prefix' => 'api'], function ($router) {
         $router->post('contacts/batchUpdate', 'ApiContactsController@batchUpdate');
         $router->post('contacts/batchDelete', 'ApiContactsController@batchDelete');
         $router->post('contacts/setOrder', 'ApiContactsController@setOrder');
         $router->resource('contacts', 'ApiContactsController');
     });
     /**
      * Admin routes
      */
     $router->group(['namespace' => $this->namespace, 'prefix' => 'admin', 'middleware' => ['auth']], function ($router) {
         //List Contact
         $router->get('contacts', ['as' => 'contacts', 'uses' => 'AdminContactsController@getIndex', 'permission' => 'contacts_manage']);
         //Create Contact
         $router->get('contacts/create', ['as' => 'create_contacts', 'uses' => 'AdminContactsController@getCreate', 'permission' => 'contacts_manage']);
         $router->post('contacts', ['as' => 'create_contacts', 'uses' => 'AdminContactsController@postCreate', 'permission' => 'contacts_manage']);
         //Edit Contact
         $router->get('contacts/{id}/edit', ['as' => 'edit', 'uses' => 'AdminContactsController@getEdit', 'permission' => 'contacts_manage']);
         $router->post('contacts/{id}', ['uses' => 'AdminContactsController@postEdit', 'permission' => 'contacts_manage']);
         $router->get('contacts/export', ['uses' => 'AdminContactsController@export', 'permission' => 'contacts_manage']);
         $router->resource('admin/contacts', 'AdminContactsController');
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->pattern('user', '[0-9]+');
     $router->bind('user', function ($value) {
         return User::where('id', $value)->limit(1)->first();
     });
     parent::boot($router);
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot(Router $router)
 {
     if (!$this->app->routesAreCached()) {
         require realpath(base_path('app/Clusters/AuthCluster/Resources/auth_cluster_routes.php'));
     }
     $router->bind('userName', function ($username) {
         return \App\Clusters\AuthCluster\Models\User::whereUsername($username)->firstOrFail();
     });
 }
Example #21
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->model('pieces', 'App\\Piece');
     $router->bind('studios', function ($slug) {
         return Studio::where('slug', $slug)->firstOrFail();
     });
     $router->model('events', 'App\\Event');
     parent::boot($router);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     //$router->model('genre', 'Unicorn\Genre');
     $router->bind('genre', function ($id) {
         return \Unicorn\Genre::with('albums')->where('id', $id)->first();
     });
     parent::boot($router);
 }
 /**
  * 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('license', function ($url) {
         return License::where('url', '=', $url)->first();
     });
 }
Example #24
0
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     // versione modificata
     $router->bind('articles', function ($id) {
         return \App\Article::where('id', $id)->firstOrFail();
     });
     parent::boot($router);
 }
Example #25
0
 /**
  * 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('topics', function ($slug) {
         return Topic::where('slug', $slug)->firstOrFail();
     });
     $router->bind('users', function ($slug) {
         return User::where('username', $slug)->firstOrFail();
     });
     $router->bind('posts', function ($slug) {
         return Post::where('slug', $slug)->with(['user', 'votes', 'comments'])->firstOrFail();
     });
     $router->bind('comments', function ($id) {
         return Comment::find($id);
     });
 }
 /**
  * @param Router $router
  */
 protected function RegisterRouteModel(Router $router)
 {
     /**
      * 模块
      */
     $router->bind('module', function ($moduleId) {
         return $this->app->make(IAclModule::class)->getModule($moduleId);
     });
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //
     // versione modificata
     // prendo dalla richiesta fatta su url "http://laravel.app/partecipants/1", l'id = id selezionato
     $router->bind('partecipants', function ($id) {
         return \App\Partecipant::where('id', $id)->firstOrFail();
     });
     parent::boot($router);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //parent::boot($router);
     //versione semplice
     // versione modificata
     $router->bind('users', function ($id) {
         return \App\User::where($id)->firstOrFail();
     });
     parent::boot($router);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     $router->model('partecipants', \App\Partecipant::class);
     /* versione semplice */
     $router->bind('partecipants', function ($id) {
         /*versione con opzioni specifiche*/
         return \App\Partecipant::where('id', $id)->FirstOrFail();
     });
     parent::boot($router);
 }
 /**
  * Define your route model bindings, pattern filters, etc.
  *
  * @param  \Illuminate\Routing\Router  $router
  * @return void
  */
 public function boot(Router $router)
 {
     //Versione semplice
     $router->model('partecipanti', \App\Partecipante::class);
     // se devo mettere filtri anche su campi diversi da id
     $router->bind('partecipanti', function ($id) {
         return \App\Partecipante::where('id', $id)->firstOrFail();
     });
     parent::boot($router);
 }