【问题标题】:ReflectionException in Route.php line 335: Function () does not exist don't know whyReflectionException in Route.php line 335: Function() does not exist 不知道为什么
【发布时间】:2017-06-07 07:33:20
【问题描述】:

我正在学习 Laravel 框架,并创建了一个简单的项目。

这是我的代码:

web.php

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

Route::get('/people', ['uses' => 'PeopleController@index']);

PeopleController.php

class PeopleController extends Controller
{
public function index()
{
    $users = [

        '0' =>[
            'first' => 'Alex',
            'last' => 'Shifu',
            'location' => 'Gotham'
        ]
    ];

    return view('people.index' , compact('people'));
}
}

index.blade.php

@foreach($people as $peep)
    <li>{!! $peep['first'] !!}</li>
@endforeach

这些是我面临的错误:

在 RouteCollection.php 第 161 行 Router.php 第 766 行中的 RouteCollection->match(object(Request)) Router->findRoute(object(Request)) 在 Router.php 第 621 行 Router->dispatchToRoute(object(Request)) 在 Router.php 第 607 行 Kernel.php 第 268 行中的 Router->dispatch(object(Request)) Kernel->Illuminate\Foundation\Http{closure}(object(Request)) in Pipeline.php 第 53 行 Pipeline->Illuminate\Routing{closure}(object(Request)) in CheckForMaintenanceMode.php 第 46 行,位于 CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php 第 137 行 Pipeline->Illuminate\Pipeline{closure}(object(Request)) in Pipeline.php 第 33 行 Pipeline->Illuminate\Routing{closure}(object(Request)) in Pipeline.php 第 104 行位于 Kernel.php 的 Pipeline->then(object(Closure)) 第 150 行 Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php 第 117 行位于 Kernel->handle(object(Request)) in index.php 第 54 行 require_once('C:\wamp64\www\MyApp\public\index.php') 在 server.php 第 21 行

【问题讨论】:

    标签: php laravel


    【解决方案1】:

    我看到的唯一问题是您必须在 index() 方法中将 $users 更改为 $people。

    除此之外,一切看起来都很好。

    【讨论】:

      猜你喜欢
      • 2022-11-09
      • 2016-09-03
      • 1970-01-01
      • 2017-03-01
      • 2019-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      相关资源
      最近更新 更多