Mysql – laravel REST api post method

eloquentlaravelmysqlrest

im making an api in laravel but when i send from a post request it display nothing it work only when i send the values in the url what im i doing wrong here is my code !

$user = new userInscription;

            $user->nom = Request::get('name');
            $user->pseudo = Request::get('pseudo');
            $user->userId = Request::get('userId');
            $user->hasFiat = Request::get('hasFiat');
            $user->optin = Request::get('optin');
            $user->mail = Request::get('mail');

            $pseudo = Input::get('pseudo');
            $userId = Input::get('userId');
            $hasFiat = Input::get('hasFiat');

    if($pseudo == '' || $hasFiat == '' )
        {
            return Response::json( array(
            'status'  => 'ko',
            'message'  => 'missing mandatory parameters')
            );
        }

    else if($userId == '')
        {
            if( $user->save() )
            {
                $id = DB::table('user')
                ->where('pseudo','LIKE',$pseudo)
                ->pluck('userId');

                return Response::json(array(
                    'status'  => 'ok',
                    'message'  => 'success',
                    'userId' => $id
                ));
            }
            else
            {
                return Response::json(array(
                    'message'  => 'error while saving this user !!',   
                ));
            }
        }

Best Solution

Laravel REST-ful (Resourceful) controlllers has pre-configured routes (can be re-configured):

According to : http://laravel.com/docs/controllers#resource-controllers

+-----------+---------------------------+---------+------------------+
|   Verb    |           Path            | Action  |    Route Name    |
+-----------+---------------------------+---------+------------------+
| GET       | /resource                 | index   | resource.index   |
| GET       | /resource/create          | create  | resource.create  |
| POST      | /resource                 | store   | resource.store   |
| GET       | /resource/{resource}      | show    | resource.show    |
| GET       | /resource/{resource}/edit | edit    | resource.edit    |
| PUT/PATCH | /resource/{resource}      | update  | resource.update  |
| DELETE    | /resource/{resource}      | destroy | resource.destroy |
+-----------+---------------------------+---------+------------------+

Referencing the table each of the Verb must correspond to the action method in the controller.

For example if your Resourceful Route is registered as:

Route::resource('user', 'userInscriptionController');

Then to POST to user resource, you need to have userInscriptionController@store action (i.e. method called store() in your userInscriptionController.

To avoid manually creating each of these actions, you can use Laravel's artisan controller:make

php artisan controller:make userInscriptionController

which will generate all these actions for you, then you just need to fill in your logic to complete the resource.