Laravel 相同的路由,不同的控制器
我想要一般主页和登录用户的不同主页
我在谷歌上搜索了很多,但我找不到在我的 if 语句中输入什么
I would like to have general home page
and a different homepage for logged-in users
I search a lot on google but I can't find what to put in my if statement
我尝试过这样的事情:
Route::get('/', array('as'=>'home', function(){
if (!Auth::check()) {
Route::get('/', array('uses'=>'homecontroller@index'));
}
else{
Route::get('/', array('uses'=>'usercontroller@home'));
}
}));
我也尝试过类似的东西:
I also try with something like:
return Controller::call('homecontroller@index');
但它似乎不适用于laravel 4
but it seems it's not for laravel 4
我尝试了很多其他的东西,所以我认为这更像是一个误解问题
I tried a lot of other things so I think it's more a misconception problem
如果你有任何线索
感谢您的帮助
推荐答案
我能想到的最简单的解决方案是:
The most simple solution I can think of is:
<?php
$uses = 'HomeController@index';
if( ! Auth::check())
{
$uses = 'HomeController@home';
}
Route::get('/', array(
'as'=>'home'
,'uses'=> $uses
));
或者您可以将 url/路由到方法 index() 并在其中执行 Auth::check().
Or you can just route the url / to method index() and do the Auth::check() in there.
相关文章