为什么Laravel不会将我的变量传递给刀片模板?

I'm using Laravel 5.2. In routes.php, I have:

Route::get('test', function() {
    $events = App\Event::get();
    return view('test', $events);
});

In test.blade.php, I have:

<?php print_r($events) ?>

And I get:

ErrorException in ....php line 11: Undefined variable: events (View: .../test.blade.php)

My get() statement is working properly (print_r($events) works in routes.php). Why isn't it getting passed to the blade template?

You are not passing the data correctly. Try this instead:

return view('test', ['events' => $events]);

You have other options too. For example:

return view('test', compact('events'));

return view('test')->with(['events' => $events]);

Source: https://laravel.com/docs/5.2/views

return view('test', ['events' => $events]);

you can also display value like this in blade (for testing)

{{ dd($events) }}