【发布时间】:2021-04-12 19:52:09
【问题描述】:
web.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
【问题讨论】:
-
因为您发出了
/test路由发布请求,并且您似乎想通过get请求访问它 -
test必须使用get方法 -
那是我的错,我尝试使用 post 测试它,但不起作用,就像使用 get 请求一样。我现在编辑了原始代码。
-
这也没有解释为什么/返回welcome.blade.php,因为它应该返回invoices.index.blade.php 我试图做一个新项目,看看是否会有区别,还是一样的。
-
看起来在这个端口中打开了另一个项目尝试在另一个端口中运行您当前的项目,例如
php artisan --port=8080