laravel - 未找到显示 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
解决方案
检查您的路线定义。它应该是这样的:
Route::get('/', 'PagesController@index');
或者
Route::get('/', [PagesController::class, 'index']);
你也可以试试:
Route::view('/', 'invoices.index');
推荐阅读
- arrays - 如何使用 listbox.selecteditem 继续使用数组
- php - 使用不同的角色登录(根据用户类型重定向到不同的页面)
- bash - 在 sshd.conf 末尾添加一行
- sql - 在 SQL 表中查找双字节空格
- javascript - 点击包装加载问题
- r - 为什么即使我之前已经附加了数据框,我也不能在“for循环”中更改数据框的值?
- java - 尝试使用 Java 高级 REST 客户端查询 Long 类型时出现问题
- javascript - addEventListener 不适用于动态加载内容
- javascript - 如何在 Node.JS 中将原始命令发送到收据打印机?
- python-3.x - 即使重新安装了正确的版本,也会出现“OSError: [WinError 193] %1 is not an valid Win32 application”错误