Category with Parent_id

public function up(): void { Schema::create('categories', function (Blueprint $table) { $table->id(); $table->foreignId('team_id')->constrained('teams'); $table->string('name'); $table->string('slug')->unique(); $table->foreignId('parent_id')->nullable()->constrained('categories'); $table->string('image')->nullable(); $table->boolean('active')->default(true); $table->longText('description')->nullable(); $table->timestamps(); }); } protected $fillable =[ 'team_id', 'name', 'slug', 'parent_id',
'image', 'active', 'description', ]; public function team(): BelongsTo { return $this->belongsTo(Team::class); } public function parent(): BelongsTo { return $this->belongsTo(Category::class, 'parent_id'); } public function child():HasMany { return $this->hasMany(Category::class, 'parent_id'); } public function products() : BelongsToMany { return $this->belogsToMany(Product::class); } We get errors like the picture attached.
No description
2 Replies
Mr. Phearum
Mr. PhearumOP12mo ago
Error "Field 'team_id' doesn't have a default value" when use select relationship function.
David | Fortune Validator
did you find the solution. I have the same problem and I swear I've followed everything.
Want results from more Discord servers?
Add your server