Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created March 12, 2019 18:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/f2cdb08b419b573803a5519ae1d6bf7f to your computer and use it in GitHub Desktop.
Save parzibyte/f2cdb08b419b573803a5519ae1d6bf7f to your computer and use it in GitHub Desktop.
<?php
namespace App\Http\Controllers;
use App\Area; # Nuestro modelo
class AreasController extends Controller
{
public function agregar(GuardarArea $peticion)
{
$area = new Area; # Crear nuevo modelo
# Ponerle los datos para guardar
$area->nombre = $peticion->nombre;
# Guardar en BD
$area->save();
# ==================================
# Aquí tenemos el id recién guardado :)
# ==================================
$idAreaRecienGuardada = $area->id;
# Y podemos obtener cualquier propiedad, pues está refrescado
# Aquí ya puedes hacer lo que quieras con el id
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment