I believe that the best alternative is to use the framework’s own resource for this id
that you want to spend.
parameters by URL and findOrFail
Controller:
public function anyEdit($id)
{
$usuario = Usuario::findOrFail($id);
return View::make('...', ['usuario' => $usuario]);
}
View:
{{ Form::model($usuario); }}
In the case of the exemplified Controller, the method findOrFail
ensures that the user must exist in the bank at the time of editing it.
Passing the Hidden input, you run the risk of someone editing the data (with the developer tool for example) and causing problems for your programming.
In the case of findOrFail
catching the id
by the url usuario/edit/1
, if it puts a non-existent id, the Laravel
will return an exception.
In the case of Form::model()
, we pass the user, to be able to automatically fill the fields with the desired value.
Security with Input Hidden
You can apply extra security when passing data through the Hidden input.
Suppose you want to validate that field of input hidden
and ensure that the ID exists in the database. You can use validation exists
for that reason:
$rules = [
'hidden_id' => 'required|exists:tabela,id_dessa_tabela'
];
Validator::make(Input::all(), $rules);
Level Control
And in a third case let’s imagine that you have the model Produto
. And you have two types of user in the system (administrator and common).
The common cannot edit the field usuario_id
of Produto
; The administrator may.
You can use the method reguard
to protect model data. And unguard
to undo the protection.
You can do something like this:
class BaseController extends Controller
{
public function __construct()
{
if (Auth::user()->nivel !== 'administrador') {
Produto::reguard();
}
}
}
In the Laravel documentation you can explain about Session http://laravel.com/docs/5.0/session
– FernandoLopes