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

查看:41
本文介绍了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.

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

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