lundi 4 septembre 2017

Laravel - Delete if no relationship exists

Below is the one of the model. I would like to delete a Telco entry only if no other model is referencing it? What is the best method?

namespace App;

use Illuminate\Database\Eloquent\Model;

class Telco extends Model
{
 public function operators() {
    return $this->hasMany('App\Operator');
 }

 public function packages() {
    return $this->hasMany('App\Package');
 }

 public function topups() {
    return $this->hasMany('App\Topup');
 }

 public function users() {
    return $this->morphMany('App\User', 'owner');
 }

 public function subscribers() {
    return $this->hasManyThrough('App\Subscriber', 'App\Operator');
 }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire