Search code examples
phppostlaravelget

How can I receive values using POST method in laravel?


I'm trying to get a value on a server created in laravel, this value is an ID and password for security should receive the value in the body and not in the query, ie, need to use the POST method. My problem is that only receive values ​​using the GET method.

Route

Route::get('tecnico/{idUnico}/{contrasena}', array('uses' => 'TecnicoController@loginTecnico'));

TecnicoController

class TecnicoController extends BaseController{

public function loginTecnico($idUnico, $contrasena){
     ....
     //return a JSOn RESPONSE
    }    
}

How would stay the same code but with POST method?


Solution

  • If you intend to have the ID and password as post variables, with the url as https://yoursite.com/tecnico then your route should be:

    Route::post('tecnico', array('uses' => 'TecnicoController@loginTecnico'));
    

    Then you can get the post variables in your action like so:

    class TecnicoController extends BaseController{
    
    public function loginTecnico(){
    
        // assuming your post variables are named idUnico and contrasena
        $id = Input::get('idUnico');
        $password = Input::get('contrasena);
    
        }    
    }
    

    You can read more about it in the Laravel docs: Routing & Requests & Input