本文整理汇总了PHP中Illuminate\Support\Facades\Route::bind方法的典型用法代码示例。如果您正苦于以下问题:PHP Route::bind方法的具体用法?PHP Route::bind怎么用?PHP Route::bind使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Facades\Route
的用法示例。
在下文中一共展示了Route::bind方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
Route::bind('slug', function ($value) {
return Project::where('slug', '=', $value)->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)
{
parent::boot($router);
Route::bind('items', function ($id) {
return Item::forCurrentUser()->findOrFail($id);
});
Route::bind('categories', function ($id) {
return Category::forCurrentUser()->findOrFail($id);
});
}
示例3: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
parent::boot();
Route::bind('article', function ($slug) {
if (!Auth::user()) {
return Article::published()->slug($slug)->first();
}
return Article::where('slug', $slug)->first() ?: Article::findOrFail((int) $slug);
});
Route::bind('tag', function ($slug) {
if (!Auth::user()) {
return Tag::slug($slug)->first();
}
return Tag::where('slug', $slug)->first() ?: Tag::findOrFail((int) $slug);
});
Route::bind('page', function ($id) {
return Page::find($id);
});
}
示例4: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
// $router->model('accounts', Account::class);
Route::bind('accounts', function ($id) {
return Account::forCurrentUser()->findOrFail($id);
});
Route::bind('budgets', function ($id) {
return Budget::forCurrentUser()->findOrFail($id);
});
Route::bind('transactions', function ($id) {
return Transaction::forCurrentUser()->findOrFail($id);
});
Route::bind('favouriteTransactions', function ($id) {
return FavouriteTransaction::forCurrentUser()->findOrFail($id);
});
Route::bind('savedFilters', function ($id) {
return SavedFilter::forCurrentUser()->findOrFail($id);
});
}
示例5: boot
/**
* Define your route model bindings, pattern filters, etc.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function boot(Router $router)
{
parent::boot($router);
Route::bind('exercises', function ($id) {
return Exercise::forCurrentUser()->findOrFail($id);
});
Route::bind('exerciseEntries', function ($id) {
return ExerciseEntry::forCurrentUser()->findOrFail($id);
});
Route::bind('menuEntries', function ($id) {
return MenuEntry::forCurrentUser()->findOrFail($id);
});
Route::bind('exerciseSeries', function ($id) {
return ExerciseSeries::forCurrentUser()->findOrFail($id);
});
Route::bind('foods', function ($id) {
return Food::forCurrentUser()->findOrFail($id);
});
Route::bind('recipes', function ($id) {
return Recipe::forCurrentUser()->findOrFail($id);
});
Route::bind('exerciseTags', function ($id) {
return Tag::forCurrentUser()->where('for', 'exercise')->findOrFail($id);
});
Route::bind('recipeTags', function ($id) {
return Tag::forCurrentUser()->where('for', 'recipe')->findOrFail($id);
});
Route::bind('foodUnits', function ($id) {
return Unit::forCurrentUser()->where('for', 'food')->findOrFail($id);
});
Route::bind('exerciseUnits', function ($id) {
return Unit::forCurrentUser()->where('for', 'exercise')->findOrFail($id);
});
Route::bind('timers', function ($id) {
return Timer::forCurrentUser()->findOrFail($id);
});
Route::bind('activities', function ($id) {
return Activity::forCurrentUser()->findOrFail($id);
});
Route::bind('weights', function ($idOrDate) {
if (strrpos($idOrDate, '-')) {
//parameter is the date of the entry
$weight = Weight::forCurrentUser()->where('date', $idOrDate)->first();
} else {
//parameter is the id of the entry
$weight = Weight::forCurrentUser()->findOrFail($idOrDate);
}
return $weight;
});
/**
* $parameter is either the id or the date
*/
Route::bind('journal', function ($parameter) {
/**
* @VP:
* Is there a better way to check if the $parameter is an
* id or a date? When I tried using Carbon to create an object from
* the parameter, it threw an exception when the $parameter was the id,
* whereas I just wanted a boolean.
*/
if (strrpos($parameter, '-')) {
//$parameter is the date of the entry
$journal = Journal::forCurrentUser()->where('date', $parameter)->first();
} else {
//$parameter is the id of the entry
$journal = Journal::forCurrentUser()->findOrFail($parameter);
}
return $journal;
});
}