本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
});
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}