Jan 17, 2018
0
Level 1
Display and saving form for different user’s roles
I have a web form with many fields (about 20) for filling. Admin can view and edit all fields. Managers can view 15 fields and can edit 10 of them.
How can i disable necessary fields for managers in blade template? Do i have to create 20 permissions and check every field?
@can ('edit_name')
{!! Form::text('name') !!}
@else
{!! Form::text('name', ['disabled' => 'disabled']) !!}
@endif
And the second question. How can i check, that manager didn’t post restricted fields in request? I see one way: check user’s role and fill each field, because i can’t change property $fillable in my model
if ($isAdmin) {
$record->name = $request->get('name');
$record->date = $request->get('date');
...
} elseif ($isManager) {
$record->name = $request->get('name');
$record->otherField = $request->get('otherField');
...
}
Is it right? Can you develop forms like this?
Please or to participate in this conversation.