lundi 23 mai 2016

Laravel Scope based on BelongsTo Relationship

I have 2 Models, a ServiceInstances That Belongs to a ServiceTypes. Service type determines some things and among them the service length

In ServiceInstances I am trying to implement this "pseudo" logic:

I need to get $this->serviceType()->length, but relationship method fails

public function scopeExpired($query) {
    $length = $query->serviceType()->length;
    return $query->where('created_at', '<', Carbon::now()->subDays($length));
}

Any ideas ?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1YT49Td
via IFTTT

Aucun commentaire:

Enregistrer un commentaire