首页 > 解决方案 > 未找到显示 welcome.blade.php 或 404 的视图

问题描述

网页.php

use App\Http\Controllers\PagesController;
use Illuminate\Support\Facades\Route;

Route::get('/', PagesController::class, 'index');
Route::get('/test', PagesController::class, 'test');

PagesController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PagesController extends Controller
{
    public function index()
    {
        return view('invoices.index');
    }

    public function test()
    {
        return view('invoices.test');
    }
}

文件夹结构

views
  invoices
    index.blade.php
    test.blade.php
  layouts
    app.blade.php
  welcome.blade.php

问题

当我运行php artisan serve并转到时,localhost:8000我看到了 welcome.blade.php 模板,当我转到 localhost:8000/test 时,我得到 404 not found。

我尝试了以下命令但没有成功。

php artisan cache:clear
php artisan route:cache

标签: laravellaravel-8

解决方案


检查您的路线定义。它应该是这样的:

Route::get('/', 'PagesController@index');

或者

Route::get('/', [PagesController::class, 'index']);

你也可以试试:

Route::view('/', 'invoices.index');

推荐阅读