L
L
Lucius Mooning2018-06-27 10:24:44
Laravel
Lucius Mooning, 2018-06-27 10:24:44

: is it possible to replace the isset($profile->phone_number) construct? $profile->phone_number: null for something less cumbersome?

Good afternoon!
The initial data is standard: there is a profile form with many fields. To create and edit, the same view is used, containing a form with fields.
Done like this:

@if( isset($form)
            {!! CollectiveForm::model($form,
                [
                     'method' => 'PATCH',
                     'class' => 'form-horizontal',
                 ]) !!}
        @else
            {!! CollectiveForm::open(
                [
                    'method' => 'POST',
                    'class' => 'form-horizontal',
                ]) !!}
        @endif

Например, код вывода полей такие:
        <div class="col-lg-12">
            {!! CollectiveForm::text('phone_number',   isset($profile->phone_number) ? $profile->phone_number : null,
            ['class' => 'form-control', 'required' => 'required', 'disabled' => $disabled ]) !!}
        </div>

        <div class="col-lg-12">
            {!! CollectiveForm::text('content',   isset($form->content) ? $form->content : null,
            ['class' => 'form-control', 'required' => 'required', 'disabled' => $disabled ]) !!}
        </div>

My question is: is it possible to replace the structure
isset($profile->phone_number) ? $profile->phone_number : null

for something less cumbersome? Or offer a radically different more convenient solution for using fields in the form.
Fields - about 30.
What do you recommend?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Koteezy, 2018-06-27
@honeymoonny

This is if PHP7+
$profile->phone_number ?? null

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question