Php laravel 4.2模型变异子
我目前正在开发一个通知系统。我目前面临的问题是,所有通知都是非个人的 我想要的是将通知保存到具有正确个性化语言的数据库中,例如,我当前有一个这样的通知 乔·布洛格斯补充比利·乔尔为项目经理 我想要的是通知到每一个不是Billy Joel的人,但是对于Billy Joel,我想发送以下内容 Joe Bloggs将您添加为项目经理 目前,我在数据透视表的同步上为项目经理保存了这样的通知Php laravel 4.2模型变异子,php,laravel,Php,Laravel,我目前正在开发一个通知系统。我目前面临的问题是,所有通知都是非个人的 我想要的是将通知保存到具有正确个性化语言的数据库中,例如,我当前有一个这样的通知 乔·布洛格斯补充比利·乔尔为项目经理 我想要的是通知到每一个不是Billy Joel的人,但是对于Billy Joel,我想发送以下内容 Joe Bloggs将您添加为项目经理 目前,我在数据透视表的同步上为项目经理保存了这样的通知 $notification = new Notification; $notification->w
$notification = new Notification;
$notification->withURI($organisation->slug);
$notification->withIsNotification(1);
$notification->regarding($organisation);
$notification->user_id = ResourceServer::getOwnerId();
$notification->withType('updated');
//die(print_r($changes));
foreach($changes['attached'] as $k => $v) {
//Loop through each new attachment to the pivot
//look for who the attachement is from the user table and then
//add the final notification details and fire the deliver method
$addedUser = User::find($v);
$addedUserName = $addedUser->first_name . " " . $addedUser->last_name;
$notification->withBody($notifcationSenderName . " added " . $addedUserName . " to the organisation " . $organisation->name);
$notification->deliver($notifyUsers);
}
我想知道,当我从数据库通过它的模型查询用户时,如果不需要个人通知,我是否能够使用模型变体返回用户的第一个和第二个名字,如果需要,然后返回“You”。这是否可能与突变有关?如果可能,如何实现?虽然我不赞成这种方法,但您确实可以在访问器中实现这一点:
公共函数getNameAttribute()
{
如果(Auth::id()=$this->id)返回“you”;
返回“{$this->first\u name}{$this->last\u name}”;
}
@Zuhran-虽然auth()
助手在4.2中不可用。这样更安全,以防没有登录用户。