2

I'm using laravel's backpack CRUD and I have a pivot table called equipment_parameter where i'm trying to save the last id from the parent equipment table. how do i get the last equipment ID to save it in Equipment_parameter pivot table ?

    public function store(StoreRequest $request)
{          
    $response= parent::storeCrud();

    // $id = $response->lastInsertId(); <-- doesn't work

    $user = EquipoParametro::create([
        'equipo_id' => Input::get("equipo_id"), <-- this works sometimes)
        'parametro_id' => Input::get("parametros")
    ]);

    return $response;
}

Equipment model

   public function parametros(){

   return $this->belongsToMany('App\Parametro','equipo_parametro','equipo_id','parametro_id')->withTimestamps();
}

1 Answers1

5

If you're looking for the ID of the entry you've just inserted, I should be able to use $this->crud->entry->id:

public function store(StoreRequest $request)
{          
    $response= parent::storeCrud();

    $id = $this->crud->entry->id; // <-- SHOULD WORK

    $user = EquipoParametro::create([
        'equipo_id' => $id,
        'parametro_id' => Input::get("parametros")
    ]);

    return $response;
}
tabacitu
  • 6,047
  • 1
  • 23
  • 37