'syntax error, unexpected identifier enum laravel
I am using LARAVEL 9. I am create enum in Enum folder and access in model. But when i am adding data i am getting this error
syntax error, unexpected identifier "GenderEnum"
Here is my code
GenderEnum.php
<?php
namespace App\Enum;
enum GenderEnum:string
{
case MALE = 'male';
case FEMALE = 'Female';
}
AdminSeeder.php
$data = [
'first_name' => 'Rishab',
'last_name' => 'goyal',
'email' => '[email protected]',
'mobile_number' => '123',
'role' => '1',
'gender' => 'male',
'password' => '123',
'profile_photo' => '',
];
Admin::addEdit($data);
Admin.php (Model)
protected $casts = [
'gender' => GenderEnum::class
];
Solution 1:[1]
There's nothing wrong with your code even in the namespace. The problem is your environment setup, maybe you are still running PHP 8.0 or below instead of PHP 8.1
Enums is a new syntax introduced in PHP 8.1, and not supported in older PHP versions. Parse error: syntax error, unexpected identifier
Solution 2:[2]
Please check 'use App\Enum' namespace is imported properly
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Thrive Digital |
| Solution 2 | Ketan Vekariya |
