【问题标题】:Laravel initial router, how to pass the controller?Laravel初始路由器,如何传递控制器?
【发布时间】:2016-06-16 21:07:35
【问题描述】:

夫人。早上好,我想配置我的 Laravel 初始路由,在 / 上工作,我不知道如何使用控制器。

我现在使用将我的初始路由重定向到 /start 路由,但我想只在 / 上使用。

请看下面我的路由器。

Route::controller("Start");
Route::controller("Search");
Route::controller("Contact");

Route::get('/', function()
{
    return Redirect::to("start");
});

我想做:

Route::get('/', function()
{
    return View::make("start.index");
});

并将 Start.php 控制器传递给这个视图,有可能吗?

有人可以帮我吗?

【问题讨论】:

  • Route::get('/', 'StartController@index');应该可以正常工作,还是您特别避免使用的解决方案?
  • @Damien,谢谢,这正是我需要的!

标签: php laravel router


【解决方案1】:
Route::get('/', 'StartController@index');

看起来像你所追求的:https://laravel.com/docs/5.2/routing

你也可以使用数组调用它,传递额外的参数:

Route::get('/', ['as' => 'start', 'uses' => 'StartController@index']);

【讨论】:

  • 谢谢@Damien,帮了大忙!
猜你喜欢
  • 2013-08-15
  • 2015-01-06
  • 1970-01-01
  • 1970-01-01
  • 2016-04-16
  • 2016-05-16
  • 2017-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多