无法在 Laravel 中调用 View:make

Can not call View:make in Laravel

无法调用View:make函数。我收到此错误:

 return View::make('fb-post.index',['users'=>$users]);

               Class 'App\Http\Controllers\View' not found

路线

  Route::get('/', 'PostController@test');

控制器

public function test()
{
  $customers = 'test';

  return View::make('fb-post.index')->with('customers', $customers);

}

我的模板文件在 view/fb-post/index.blade.php

当我打电话给

 php artisan dump-autoload

得到:

        exception 'InvalidArgumentException' with message 'Command "dump-autoload" is not defined.' in /var/www/html/laravel-test/vendor/symfony/console/Symfony/Component/Console/Application.php:549
        Stack trace:
        #0 /var/www/html/laravel-test/vendor/symfony/console/Symfony/Component/Console/Application.php(192): Symfony\Component\Console\Application->find('dump-autoload')
        #1 /var/www/html/laravel-test/vendor/symfony/console/Symfony/Component/Console/Application.php(126): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
        #2 /var/www/html/laravel-test/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(91): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
        #3 /var/www/html/laravel-test/artisan(36): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
        #4 {main}

有什么想法吗?

View 门面不在当前命名空间中。所以你要么在它前面加上 \:

return \View::make('fb-post.index', ['users' => $users]);

或者在控制器文件的顶部添加:

use View;

此外,根据您收到的错误,我假设您正在使用 Laravel 5。在这种情况下,您可以使用 view 辅助函数:

return view('fb-post.index', ['users' => $users]);