I get an error when create a table seeder using model factory in laravel 8 but I don't know where I'm going wrong here.
This is an error:
Undefined constant "App\Models\boolean"
at C:\xampp\htdocs\mason\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Factories\Factory.php:628
Here is my code:
Category.php:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Astrotomic\Translatable\Translatable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
class Category extends Model
{
use HasFactory, Translatable;
protected $with = ['translations'];
protected $translatedAttributes = ['name'];
protected $hidden = ['translattions'];
protected $casts = ['is_active' => boolean];
protected $fillable = ['parent_id', 'slug', 'is_active'];
}
CategoryFactory.php:
<?php
namespace Database\Factories;
use App\Models\Category;
use Illuminate\Database\Eloquent\Factories\Factory;
class CategoryFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Category::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition(): array
{
return array(
'name' => $this->faker->word(),
'slug' => $this->faker->slug(),
'is_active' => $this->faker->boolean(),
);
}
}
CategoryTableSeeder.php
<?php
namespace Database\Seeders;
use App\Models\Category;
use Illuminate\Database\Seeder;
class CategoryTableSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Category::factory(10)->create();
}
}