我在routes.php,
中定义了这条命名路线Route::get('/', [
'as' => 'home',
'uses' => 'PagesController@home'
]);
然后我在PagesController.php
中有这个public function home() {
return 'Welcome home!';
}
我的问题是为什么http://localhost:8000/home会产生此错误?
NotFoundHttpException in RouteCollection.php line 161:
答案 0 :(得分:4)
您尚未为网址route
创建/home
。您只创建了/
路线。
为了进一步解释您的问题,您只需使用home
命名您的路线。这意味着您可以链接到视图中的{{url()->route('home')}}
,以转到将成为您主页的网址/
。您还可以使用url()->route('home')
从任何控制器访问此路由。
如果您想访问页面/home
,则需要为此创建路线。
例如:
Route::get('/home', ['as'=>'NameUrRoute', 'uses'=>'PagesController@SamplePage']);
'as'=>'home'
只表示路线的名称。不是URI
。
答案 1 :(得分:2)
路由function upto {
if [[ -z $1 ]]; then
return
fi
local upto=$1
cd "${PWD/\/$upto\/*//$upto}"
}
_upto()
{
local cur=${COMP_WORDS[COMP_CWORD]}
local d=${PWD//\//\ }
COMPREPLY=( $( compgen -W "$d" -- "$cur" ) )
}
complete -F _upto upto
为name
,因此您可以从控制器访问它,或使用home
进行查看。但网址中的实际地址为URL::route('home')