无法将Illuminate \ Routing \ Route类的对象转换为字符串

时间:2018-11-21 11:23:51

标签: php laravel-5 laravel-5.7

我正在尝试做一些非常简单的事情。

Route::get('/', function () {
    return Route::view('/welcome', 'welcome');
});

我只希望它加载welcome视图并将URI更改为/welcome。但是,您可以看到它不断抛出错误Object of class Illuminate\Routing\Route could not be converted to string

我一分钟都没碰过Laravel,我有点想重新尝试一下,并试图建立一个简单的网站。我可能会错过一些显而易见的东西,但我不知道它可能是什么。

任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我想你的意思是

Route::redirect('/', '/welcome', 301);
Route::view('/welcome', 'welcome');

//one view like resources/views/welcome.blade.php
Route::get('/', function () {
    return view('welcome');
});

但是实际上,我们通常使用.htaccess重定向请求,因为在框架中执行任何操作之前,您必须加载所有需求。

答案 1 :(得分:0)

您可以使用

 Route::view('/','welcome');

或使用

 Route::get('/', function () {
  return view('welcome');
});

我猜您正在混合两种不同的语法。

[http://www.expertphp.in/article/laravel-5-5-new-feature-route-view-and-route-redirect-method-with-example]

相关问题