我想做的是根据命名的路由返回“ post type”。我不想使用像MATCH (L:Location)
MATCH p1 = (C1:Crime {type: 'Bicycle theft'})-[:OCCURRED_AT]->(L)
MATCH p2 = (C2:Crime {type: 'Burglary'})-[:OCCURRED_AT]->(L)
MATCH p3 = (C3:Crime {type: 'Drugs'})-[:OCCURRED_AT]->(L)
WITH p1, p2, p3, C1, C2, C3,
split(C1.date, '/') as tmp1,
split(C2.date, '/') as tmp2,
split(C3.date, '/') as tmp3
WITH p1, p2, p3, C1, C2, C3,
datetime(tmp1[2] + '-' + tmp1[1] + '-' + tmp1[0]) as dt1,
datetime(tmp2[2] + '-' + tmp2[1] + '-' + tmp2[0]) as dt2,
datetime(tmp3[2] + '-' + tmp3[1] + '-' + tmp3[0]) as dt3
WHERE dt1 < dt2 AND
dt1 > dt3
RETURN p1, p2, p3
这样的路由参数。
web.php
Route::get('/{post-type}');
PostController
Route::prefix('/category/{category}')->group(function () {
Route::get('/article','PostController@topPostType')->name('articlePostType');
//Route::get('/video','PostController@topPostType')->name('videoPostType');
});
在PostController中,假设public function topPostType(Category $category, Request $request)
{
return $this->getPostType($request);
}
protected function getPostType(Request $request)
{
if ($request->route()->name('videoPostType')) {
return 'video';
} elseif ($request->route()->name('articlePostType')) {
return 'article';
} else{
return 'Not working';
}
}
方法根据路由名称返回一个字符串类型的字符串。问题是,即使我注释掉名为route的videoPostType或使用名为route的articlePostType,我仍然在getPostType()
方法中返回“视频”。
答案 0 :(得分:0)
您应该使用named()
而不是name()
if ($request->route()->named('profile')) {
//
}