-
-
Save parzibyte/f2cdb08b419b573803a5519ae1d6bf7f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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