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 相同的路由,不同的控制器


基础教程推荐
- PHPUnit 的 Selenium 2 文档到底在哪里? 2022-01-01
- php中的foreach复选框POST 2021-01-01
- php中的PDF导出 2022-01-01
- 如何在数学上评估像“2-1"这样的字符串?产生“1"? 2022-01-01
- php 7.4 在写入变量中的 Twig 问题 2022-01-01
- 使用 scandir() 在目录中查找文件夹 (PHP) 2022-01-01
- 主题化 Drupal 7 的 Ubercart “/cart"页 2021-01-01
- Yii2 - 在运行时设置邮件传输参数 2022-01-01
- Web 服务器如何处理请求? 2021-01-01
- 将变量从树枝传递给 js 2022-01-01