2016-07-21 10 views
0

以下の$ fieldsという配列に条件文を含める必要があります。フィールドの配列に条件文を追加しますか?

$fields = [ 
    'program_id'  => [ 
     'type'  => 'select', 
     'label'  => 'Program', 
     'opts'  => ["One", "Two", "Three"], 
    ], 
    'name'   => [ 
     'label' => 'Job Name' 
    ], 
    'start_date'   => [ 
     'class' => 'date-picker', 
     'label' => 'Job Starts' . $req, 
     'val' => $job->start_date ? dateToPicker($job->start_date) : null 
    ], 
    'end_date'   => [ 
     'class' => 'date-picker', 
     'label' => 'Job Ends' . $req, 
     'val' => $job->end_date ? dateToPicker($job->end_date) : null 
    ], 
    'section'   => [ 
     'type' => 'hidden', 
     'val' => 'details' 
    ], 
]; 
if (!$job->id && $program) 
{ 
    $fields['job_copy'] = [ 
     'label'  => 'Copy Job From', 
     'type'  => 'select', 
     'textAsValue' => false, 
     '_comment' => 'Selecting a job here will copy all job information except the name.', 
     'opts'  => array_replace([0 => '-- Select Job --'], $program->jobs()->lists('name', 'id')->all()) 
    ]; 
} 
$fields[] = [ 
    'type' => 'submit', 
    'label' => "Save", 
    'class' => 'btn btn-primary !important' 
]; 

}

私はそれがフォームに表示された第1のものとなるように、先頭に条件文を移動する必要があります。しかし、それを上に移動すると消えます。条件付き小切手を現在表示されている下部のフォームとは対照的に、フォームの上部に統合するにはどうすればよいですか?

答えて

1
$fields = []; 
if (!$job->id && $program) 
{ 
    $fields['job_copy'] = [ 
     'label'  => 'Copy Job From', 
     'type'  => 'select', 
     'textAsValue' => false, 
     '_comment' => 'Selecting a job here will copy all job information except the name.', 
     'opts'  => array_replace([0 => '-- Select Job --'], $program->jobs()->lists('name', 'id')->all()) 
    ]; 
} 

$fields2 = [ 
    'program_id'  => [ 
     'type'  => 'select', 
     'label'  => 'Program', 
     'opts'  => ["One", "Two", "Three"], 
    ], 
    'name'   => [ 
     'label' => 'Job Name' 
    ], 
    'start_date'   => [ 
     'class' => 'date-picker', 
     'label' => 'Job Starts' . $req, 
     'val' => $job->start_date ? dateToPicker($job->start_date) : null 
    ], 
    'end_date'   => [ 
     'class' => 'date-picker', 
     'label' => 'Job Ends' . $req, 
     'val' => $job->end_date ? dateToPicker($job->end_date) : null 
    ], 
    'section'   => [ 
     'type' => 'hidden', 
     'val' => 'details' 
    ], 
]; 
$fields = array_merge($fields,$fields2); 
$fields[] = [ 
    'type' => 'submit', 
    'label' => "Save", 
    'class' => 'btn btn-primary !important' 
]; 
+0

ライフセーバー。ありがとう! –

関連する問題