在我的数据库中,我有两个表notification
和alertFrequency
。通知具有字段id and website_url
,警报频率具有id
和notification_id
。两个表的模型都是一对多的。通知可以有一个或多个alertFrequency
。
class Notification extends Model {
public function alertFrequencies() {
return $this - > belongsToMany('AlertFrequency::class');
}
}
namespace App;
use Illuminate\ Database\ Eloquent\ Model;
class AlertFrequency extends Model {
protected $table = 'alertFrequencies';
public function notification() {
return $this - > belongsTo(Notification::class);
}
}
在通知模型中,我编写了一个名为alert的函数,它将为我提供与特定Websie相关的最新警报。
public function alert(){
$alert_frequency = AlertFrequency::find('notification_id')->first();
$o_notification = $this->alertFrequencies()->where('notification_id',$alert_frequency->id)
->select('created_at')->orderBy('created_at')->first();
if($alert_frequency ==null){
return false;
}
return created_at;
}
这是提取数据的正确方法吗?我将不胜感激任何建议和帮助?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句