我使用 Laravel 和 Sentinel 进行身份验证。
身份验证工作正常,我可以使用 Sentinel 登录并取回用户,我可以看到所有用户的字段。
但是,我无法访问它的关系(哨兵角色除外)。
$user = Sentinel::findById($userId);
dd($user->telephones); // returns null
$user = App\User::find($userId);
dd($user->telephones); // displays a dump of the associated eloquent collection
Run Code Online (Sandbox Code Playgroud)
有没有办法从 Sentinel 中检索 eloquent User 以便我可以查看它的关系?
我的用户可以指定是否立即向他们发送通知,或者每天收到任何待处理通知的通知。
以下内容适用于手动测试;现在我想围绕此编写一个功能测试,以确保发送电子邮件而不是短信或什么也没有。
public function test_instant_notification_is_sent(): void
{
Mail::fake();
$this->user = $user = factory(User::class)->create();
$this->user->update(
[
'notification_frequency' => 'instant',
'notification_method' => 'email',
'notification_email' => $this->email,
]
);
$this->user->save();
$email = ['subject' => 'subject', 'data' => 'data'];
$sms = 'Test Notification';
$database = ['some' => 'data'];
$this->user->notify(new TestNotification($email, $sms, $database));
Mail::assertSent(MailMessage::class);
}
Run Code Online (Sandbox Code Playgroud)
我已经写了一个TestNotification来配合它。
class TestNotification extends Notification
{
use Queueable;
public function __construct(array $email, string $sms, array $database)
{
$this->email = $email;
$this->sms = $sms;
$this->database = $database;
}
public …Run Code Online (Sandbox Code Playgroud)