Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 762
None Avatar asked Mar 01 '26 14:03

None


1 Answers

Use correct syntax:

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

Or:

$additional = new Feature;
$additional->firstOrCreate($data);
like image 85
Alexey Mezenin Avatar answered Mar 03 '26 02:03

Alexey Mezenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!