Laravel same route, different controller(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 相同的路由,不同的控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Laravel 相同的路由,不同的控制器
基础教程推荐
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
