It's my first time using blade and I'm a little confused with this. I need to show a form like what it comes with the default edit-add view in Voyager, but I need to display some inputs based on roles. I am filtering by the current user that is logged in and that is working fine, but I need to hide/display some inputs of the form based on that.
How can I accomplish this in the blade view?
Here is how Voyager take the data in the blade view:
@php
$dataTypeRows = $dataType->{(isset($dataTypeContent->id) ? 'editRows' :'addRows' )};
@endphp
@foreach($dataTypeRows as $row)
<!-- GET THE DISPLAY OPTIONS -->
@php
$options = json_decode($row->details);
$display_options = isset($options->display) ? $options->display : NULL;
@endphp
@if ($options && isset($options->formfields_custom))
@include('voyager::formfields.custom.' . $options->formfields_custom)
@else
<div class="form-group @if($row->type == 'hidden') hidden @endif @if(isset($display_options->width)){{ 'col-md-' . $display_options->width }}@else{{ '' }}@endif" @if(isset($display_options->id)){{ "id=$display_options->id" }}@endif>
{{ $row->slugify }}
<label for="name">{{ $row->display_name }}</label>
@include('voyager::multilingual.input-hidden-bread-edit-add')
@if($row->type == 'relationship')
@include('voyager::formfields.relationship')
@else
{!! app('voyager')->formField($row, $dataType, $dataTypeContent) !!}
@endif
@foreach (app('voyager')->afterFormFields($row, $dataType, $dataTypeContent) as $after)
{!! $after->handle($row, $dataType, $dataTypeContent) !!}
@endforeach
</div>
@endif
@endforeach
If my table 'example' contains: id, name, address and phone. How do I display in this view form only inputs for name and address?
Thanks in advance.
You should try this:
public function edit(Request $request, $id)
{
$user = Example::find($id);
return view(‘viewname’,compact(‘user’));
}
edit-add.blade.php
<input type = “text” name=”name” value=”@if(isset($user->name)){{ old('name', $user->name) }}@else{{old('name')}}@endif”>
<input type = “text” name=”name” value=”@if(isset($user->address)){{ old('address', $user->address) }}@else{{old('address')}}@endif”>