Error in path when recognizing route request

Asked

Viewed 764 times

0

Even after the route definition, when performing a post, the application occurs the error of "404 not foud". However, in this same, when accessing the index, I can obtain data from my database. Theoretically, it was also not to access.

I’ll post the code for you to analyze

Route::get('/personal', 'PersonalController@index');

Route::post('/personal/new', 'PersonalController@store');

Route::get('/personal/remove/{id}', 'PersonalController@destroy');

My controller:

public function store(PersonalRequest $request){

    $this->validate($request, [
        'cpf' => 'required|cpf',
    ]);

    $user = new Personal;

    $user->nome_pessoal = $request-> nome_pessoal;
    $user->dt_nascimento = $request-> dt_nascimento;
    $user->cidade = $request-> cidade;
    $user->rg = $request-> rg;
    $user->nome_pai = $request-> nome_pai;
    $user->nome_mae = $request-> nome_mae;
    $user->cpf = $request-> cpf;
    $user->log_registro = date('Y-m-d H:i:s'); // salvando bd: ano/mes/dia

    if(!$user) {
        return error_log('');
    } else {
        $user->save();
        return ('Page has been added.');
    }

}

Screenshot of the error when testing the API in Postman

inserir a descrição da imagem aqui

  • Which URL and which HTTP verb you are using to test in Postman?

  • http://127.0.0.1:8000/personal/new (doing a POST by Postman)

  • Check the name of the file containing the controller

  • Make a GET to 127.0.0.1:8000/personal works?

  • Yes. I can access it.

  • All routes are in the same file?

  • Yes. In web.php in the Routes folder

  • What is the output of php artisan route:list?

  • @Andreo Vieira http://prntscr.com/h4khoj

  • Yes, but the route list did not list the routes /personal

Show 5 more comments

2 answers

0

Try changing the order of the routes to how

Route::post('/personal/new', 'PersonalController@store');

Route::get('/personal/remove/{id}', 'PersonalController@destroy');

Route::get('/personal', 'PersonalController@index');

0

Man, Good afternoon, old the first thing to check is your route file, If you are using an api the correct one would be you create your routes in api.php and not in web.php. NOTE: remembering that if you use the routes in the.php api you have to access your domain/api/your route

second as you ta using the standard functions of the Laravel try the following

Route::resource('personal', 'PersonalController');

of this form the default routes of the Laravel will accept the predefined request types.

  • When using Resource, in the post, it returns that the Function store is not in my controller, and the same is.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.