3

I use Laravel 5.8 and have test method like this this

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:

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.

I see and read this post https://stackoverflow.com/questions/23593892/symfony-component-httpkernel-exception-notfoundhttpexception-laravel

4
  • can you run php artisan route:list and see you have got the intended route Commented Nov 23, 2019 at 13:24
  • Yes it's exists. I tested it with postman and it worked correctly. Commented Nov 23, 2019 at 13:43
  • In that case i would suggest try clearing your cache and do composer dump autoload. see if that helps Commented Nov 23, 2019 at 13:49
  • I do it but not work Commented Nov 23, 2019 at 13:52

2 Answers 2

2

Set your router like this

Route::resource('leads', 'LeadController');

Make sure LeadController placed in app/Http/Controller

Read Laravel - Route::resource vs Route::controller

Sign up to request clarification or add additional context in comments.

4 Comments

Route is true because I tested it with post man and it worked correctly
do u have teamviwer?
I know, but In our office forbidden remote to other
open the console and run this php artisan cache:clear, php artisan route:clear, composer dumpautload and check
2

I solved it. I change to config\app.php file

'url' =>'http://localhost/myscript_addres/public',

To

'url' =>'http://localhost/',

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.