【发布时间】:2021-09-01 19:33:48
【问题描述】:
我有两个模型之间的多对多关系:
用户
namespace App\Models;
class User extends Model
{
use HasApiTokens, Notifiable,hasFactory;
/**
* The attributes that are mass assignable.
*
* @var array
*/
];
}
通知
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Notification extends Model
{
/**
* @var array
*/
protected $guarded = ['id'];
use HasFactory;
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
}
我为每个模型创建了一个factory 和一个调用两个工厂的Seeder,以便创建users 并将通知附加到每个模型。
NotificationUserSeeder:
<?php
namespace Database\Seeders;
use App\Models\Notification;
use App\Models\User;
use Illuminate\Database\Seeder;
class MockNotificationUser extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
}
}
运行db:seed时出现此错误:
调用未定义的方法 Illuminate\Notifications\Notification::getConnectionName()
【问题讨论】: