dimanche 1 mai 2016

Pass value into @include by default

Long story short

How can I define a default value for a record in @include? Here is my code:

// view - questions.create
@include('questions.__answer', ['number' => 0]) // <-- 'answer' => null by DEFAULT

// view - questions.edit
@include('questions.__answer', ['number' => $index, 'answer' => $answer])

Additional details

As you see, I have create / edit views for a Question model, which contains multiple possible answers. The html code for a single answer is located in a separate partial view to eliminate code duplication. I need to reuse this view both for answer creation, where new record should be created from scratch, and editing of an existing answer, whose fields should be populated with existing data.

I certainly could pass 'answer' => null explicitly, but I prefer it to be passed implicitly.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire