Post method in ionic with Lumen


#1

Nowadays I working on sample project in Ionic 3, this project is a CRUD (Create, Read, Update, Delete).

I have a API with Lumen, and all endpoints works perfectly, I tested with Postman. This is route and controller code.

Route

$router->group(['prefix' => 'visitas'], function () use ($router) {
$router->get('/', [
    'as' => 'visitas.read', 'uses' => 'VisitaController@read'
]);

$router->get('/{id}/edit', [
    'as' => 'visita.edit', 'uses' => 'VisitaController@edit'
]);

$router->delete('/{id}', [
    'as' => 'visita.destroy', 'uses' => 'VisitaController@destroy'
]);

$router->put('/{id}', [
    'as' => 'visita.update', 'uses' => 'VisitaController@update'
]);

$router->post('/create', [
    'as' => 'visita.create', 'uses' => 'VisitaController@create'
]);
});

Controller


public function create(Request $request)
    {

        $this->validate($request, [   
            'nombre' => 'required',
            'dni' => 'required',
            'visitado_id' => 'required'
        ]);

        Visitas::create($request->all());
    }

In Ionic I have a provider with this

createVisita(data) {
    console.log(data);
    return this.http.post('http://visitas.api.app:8000/visitas/create/',data)
      .map(res => res.json())
      .toPromise();
  }

And controller look like this

newVisita() {
    this.visitasCtrl.createVisita(this.create)
    .then(createData => {
      this.createData = createData;
    })
    this.navCtrl.pop();
  }

This.create retrieve all form data but don’t save and return a url error. I think this is a promise (or something like that) error but not sure. I need to do this insert in database and then go to back view with pop().

¿Any idea what’s wrong?