I try to store the information of a form through POST
and it returns me a message:
419 Page Expired
Which doesn't happen when I use GET
.
HTML form:
<form action="{{url('guardar')}}" method="post" accept-charset="utf-8">
<label>Nombre:</label><input type="text" name="nombre"><br>
<label>Apellido:</label><input type="text" name="apellido"><br>
<label>Cedula:</label><input type="text" name="cedula"><br>
<input type="submit" value="Enviar Datos" name="">
</form>
Routes :
use proyecto\personas;
Route::get('formulario', function () {
return view('usuarios');
});
Route::post("guardar","Persona@store");
Controller Person:
public function store(Request $request)
{
$game = new personas;
$game->nombre = $request->get('nombre');
$game->apellido = $request->get('apellido');
$game->cedula = $request->get('cedula');
$game->save();
return "Guardado existoso";
}
Model people:
<?php
namespace proyecto;
use Illuminate\Database\Eloquent\Model;
class personas extends Model
{
protected $table='persona';
protected $fillable=[
'nombre','apellido','cedula',
];
}
The above generates a unique token per request so that Laravel knows and trusts it.
Consider that:
If for some reason you use a version equal to or lower than Laravel 5.5 then you must handle this proposal with this syntax:
Otherwise, that is, Laravel 5.6 or higher, then you can rely on the aforementioned syntax
References