Hello every one i got the upper error when i tried to seed my database using the below code and there are a reletion between the two tables and below is the code for it
Product::factory(3)
->for(Category::factory()->count(3))
->create();
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Category extends Model
{
use HasFactory;
public function products(): HasMany
{
return $this->hasMany(Product::class);
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Product extends Model
{
use HasFactory;
public function category(): BelongsTo
{
return $this->belongsTo(Category::class);
}
public function pimage(): HasMany
{
return $this->hasMany(Pimage::class);
}
}