Illuminate\Routing\Router::bind PHP Method

bind() public method

Add a new route parameter binder.
public bind ( string $key, string | callable $binder ) : void
$key string
$binder string | callable
return void
    public function bind($key, $binder)
    {
        if (is_string($binder)) {
            $binder = $this->createClassBinding($binder);
        }
        $this->binders[str_replace('-', '_', $key)] = $binder;
    }

Usage Example

Beispiel #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);
 }
All Usage Examples Of Illuminate\Routing\Router::bind