Send data via post

Asked

Viewed 619 times

2

I have the following method

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;
    use Validator;
    use App\Pessoa;
    class PessoaController extends Controller
   {

    public function lista( Request $request ){
            $nome     = "%".$request->input( 'nome' )."%";
            $telefone = "%".$request->input( 'telefone' )."%";
            $empresa  = $request->input( 'empresa' );
            $setor    = $request->input( 'setor' );
            $cargo    = $request->input( 'cargo' );
            $email    = "%".$request->input( 'email' )."%";
            $pessoa = Pessoa::with(['empresa', 'setor','cargo'])
                             ->where( [
                                         [ 'nm_pessoa', 'like', $nome],
                                         [ 'telefone', 'like', $telefone ],
                                         [ 'email', 'like', $email ],
                                         [ 'cd_empresa', 'like', $empresa ],
                                         [ 'cd_setor', 'like', $setor ],
                                         [ 'cd_cargo', 'like', $cargo ]
                                    ] )
                             ->get();
            return response()->json( $pessoa );

        }
}

I have the following route

Route::group(['prefix' => 'api'], function(){
    Route::group(['prefix' => 'pessoa'], function (){
         Route::get( '', 'PessoaController@lista' );
         Route::post( 'add', ['as' => 'add', 'uses' => 'PessoaController@add'] );
    });
});

I would like to send data via post, but only that gives this message here:

Symfony Component Httpkernel Exception \

Methodnotallowedhttpexception

No message

And via get it works

In the Verifycsrftoken.php file

I left like this

protected $except = [
        'api/pessoa/*'
    ];
}

And in Kernel.php

protected $middlewareGroups = [
        'web' => [
         //   \App\Http\Middleware\EncryptCookies::class,
         //   \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
          //  \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
        //    \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        //    \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

Which is not to get the token because I could not send from the customer outside the Standard

inserir a descrição da imagem aqui

  • The problem is the bar in front of the link, remove to test and warns. http://localhost/controle/api/pessoa

  • What bar? I don’t understand

  • In the POST call, in Postman. You put a bar at the end of the link. Remove it.

  • That’s right. It worked. Thank you very much

1 answer

1


You need to remove the bar in POST calls.

If there is a bar at the end, the request magically converts to GET.

http://localhost/controle/api/pessoa

I confess that I am not sure if the change of this is in the client or the server, but I believe it is the server because I have seen rules . htaccess to treat this.

This content can help with some additional things to keep your API cool.

  • Man thank you very much

Browser other questions tagged

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