[英]Laravel 5 Symfony\Component\HttpKernel\Exception\NotFoundHttpException: POST http://localhost/myproject/public/leads
I use Laravel 5.8 and have test method like this this我使用 Laravel 5.8 并有这样的测试方法
public function test_store()
{
$attribute= ['lead_name'=>'test_name','lead_family'=>'test_family'];
$this->post('/leads', $attribute);
$this->assertDatabaseHas('leads', $attribute);
}
and controller like this:和这样的控制器:
class LeadController extends Controller
{
public function store(Request $request)
{
Lead::create($request->all());
}
}
and route :和路线:
Route::resource('/leads', 'App\Http\Controller\LeadController');
When I run phpunit show me this error:当我运行 phpunit 时显示这个错误:
Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: POST http://localhost/myproject/public/leads
Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: POST http://localhost/myproject/public/leads
C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Testing\\Concerns\\InteractsWithExceptionHandling.php:118 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php:326 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php:120 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Testing\\Concerns\\MakesHttpRequests.php:375 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Testing\\Concerns\\MakesHttpRequests.php:197 C:\\wamp64\\www\\myproject\\tests\\Feature\\Customer\\LeadTest.php:38 I test
leads
URL with Postman and it work correctly.C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Testing\\Concerns\\InteractsWithExceptionHandling.php:118 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation \\Http\\Kernel.php:326 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Http\\Kernel.php:120 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework \\src\\Illuminate\\Foundation\\Testing\\Concerns\\MakesHttpRequests.php:375 C:\\wamp64\\www\\myproject\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Testing\\Concerns\\MakesHttpRequests.php:197 C:\\wamp64 \\www\\myproject\\tests\\Feature\\Customer\\LeadTest.php:38 我使用 Postman 测试
leads
URL 并且它工作正常。
I see and read this post https://stackoverflow.com/questions/23593892/symfony-component-httpkernel-exception-notfoundhttpexception-laravel我看到并阅读了这篇文章https://stackoverflow.com/questions/23593892/symfony-component-httpkernel-exception-notfoundhttpexception-laravel
Set your router like this像这样设置你的路由器
Route::resource('leads', 'LeadController');
Make sure LeadController
placed in app/Http/Controller
确保
LeadController
放置在app/Http/Controller
Read Laravel - Route::resource vs Route::controller阅读Laravel - Route::resource vs Route::controller
I solved it.我解决了。 I change to
config\\app.php
file我更改为
config\\app.php
文件
'url' =>'http://localhost/myscript_addres/public',
To到
'url' =>'http://localhost/',
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.