jer*_*lli 5 php routing controller laravel laravel-4
我想拥有一般主页和一个不同的主页,
我在谷歌上搜索很多登录用户,但我找不到要放入if语句的内容
我试过这样的事情:
Route::get('/', array('as'=>'home', function(){
if (!Auth::check()) {
Route::get('/', array('uses'=>'homecontroller@index'));
}
else{
Route::get('/', array('uses'=>'usercontroller@home'));
}
}));
Run Code Online (Sandbox Code Playgroud)
我也尝试过类似的东西:
return Controller::call('homecontroller@index');
Run Code Online (Sandbox Code Playgroud)
但似乎不适合laravel 4
我尝试了很多其他的东西,所以我认为这更像是一个误解问题
如果你有任何线索
谢谢你的帮助
在这个平台和其他论坛的讨论之后,我回来了一个紧凑的解决方案
Route::get('/', array('as'=>'home', 'uses'=> (Auth::check()) ? "usercontroller@home" : "homecontroller@index" ));
Run Code Online (Sandbox Code Playgroud)
我能想到的最简单的解决方案是:
<?php
$uses = 'HomeController@index';
if( ! Auth::check())
{
$uses = 'HomeController@home';
}
Route::get('/', array(
'as'=>'home'
,'uses'=> $uses
));
Run Code Online (Sandbox Code Playgroud)
或者您可以将url /路由到方法index()并在那里执行Auth :: check().
| 归档时间: |
|
| 查看次数: |
5836 次 |
| 最近记录: |