Question: syntax error, unexpected 'firstOrCreate' (T_STRING), expecting variable (T_VARIABLE) or '$

Question

syntax error, unexpected 'firstOrCreate' (T_STRING), expecting variable (T_VARIABLE) or '$

Answers 1
Added at 2016-12-29 14:12
Tags
Question

Im getting this error when i try to do this:

  $additional_features = $request->input('additional_features');
        foreach($additional_features as $additional_feature){
          $data = [
             'name' => $additional_feature
           ];

           $additional = new Feature::firstOrCreate($data);
        }

$additional_features is an array and i try to add that, so how many items i have in array i will have that many records.Any suggestion?

Answers
nr: #1 dodano: 2016-12-29 15:12

Use correct syntax:

$additional = Feature::firstOrCreate($data);

Or:

$additional = new Feature;
$additional->firstOrCreate($data);
Source Show
◀ Wstecz