Laravel同路,不同控制器 [英] Laravel same route, different controller

查看:167
本文介绍了Laravel同路,不同控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想有一个普通主页
和一个不同的主页登录用户

我在google上搜索了很多,但我找不到要放在我的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'));
    }
}));

我也尝试类似:

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 )。

Or you can just route the url / to method index() and do the Auth::check() in there.

这篇关于Laravel同路,不同控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆