本文整理汇总了PHP中app\models\Company::whereSlug方法的典型用法代码示例。如果您正苦于以下问题:PHP Company::whereSlug方法的具体用法?PHP Company::whereSlug怎么用?PHP Company::whereSlug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Company
的用法示例。
在下文中一共展示了Company::whereSlug方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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->bind("users", function ($slug) {
try {
$user = User::whereSlug($slug)->with("state", "user_type")->firstOrFail();
// User::with()->findOrFail($id);
return $user;
} catch (ModelNotFoundException $e) {
return abort("404");
}
});
$router->bind("students", function ($slug) {
try {
$student = User::whereSlug($slug)->with("state", "user_type")->firstOrFail();
// User::with()->findOrFail($id);
return $student;
} catch (ModelNotFoundException $e) {
return abort("404");
}
});
$router->bind("universities", function ($slug) {
try {
$university = University::whereSlug($slug)->with("students", "faculties")->firstOrFail();
// User::with()->findOrFail($id);
return $university;
} catch (ModelNotFoundException $e) {
return abort("404");
}
});
$router->bind("companies", function ($slug) {
try {
$company = Company::whereSlug($slug)->firstOrFail();
// User::with()->findOrFail($id);
return $company;
} catch (ModelNotFoundException $e) {
return abort("404");
}
});
}