Send data via post

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 just give me this message here:

  

Symfony \ Component \ HttpKernel \ Exception \

     

MethodNotAllowedHttpException

     

No message

And via get works

In the VerifyCsrfToken.php file

I left it 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,
        ],

What is not to get the token because I could not send the client out of laravel

    
asked by anonymous 08.04.2018 / 00:43

1 answer

1

You need to remove the slash on POST calls.

If there is a slash at the end, the request is magically converted to GET.

http://localhost/controle/api/pessoa

I'm not sure if the change is on the client or the server, but I believe it's from the server because I've already seen .htaccess rules to handle this.

This content can help with a few additional things to keep your API legal.

    
08.04.2018 / 03:17