SHARE
TWEET

Untitled

a guest Jul 17th, 2019 208 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace App;
  2.     use IlluminateSupportFacadesDB;
  3.  
  4.     use IlluminateDatabaseEloquentModel;
  5.  
  6.     class Occurrence extends Model {
  7.        protected $table      = 'occurrences';
  8.        protected $guarded    = [];
  9.        protected $primaryKey = 'id_occurrence';
  10.  
  11.        public function owner(){
  12.  
  13.           return $this->belongsTo(User::class, 'id_user_fk', 'id_user');
  14.  
  15.        }
  16.  
  17.        public function department(){
  18.  
  19.           return $this->belongsTo(Department::class, 'id_department_fk', 'id_department');
  20.  
  21.        }
  22.     }
  23.      
  24. $occurrence = new AppOccurrence;
  25.     => AppOccurrence {#2938}
  26.     >>> $occurrence->first()->owner;
  27.     => AppUser {#2947
  28.          id_user: 2,
  29.          name: "Jiripoqueiro",
  30.          email: "jiripoca_vaipiar@yahoo.com.br",
  31.          dateofbirth: "1985-08-15",
  32.          active: 1,
  33.          created_at: "2019-06-03 12:05:50",
  34.          updated_at: "2019-06-03 12:05:50",
  35.        }
  36.      
  37. >>> $occurrence = new AppOccurrence;
  38.     => AppOccurrence {#2970}
  39.     >>> $occurrence->first()->owner;
  40.     => null
  41.      
  42. namespace App;
  43.  
  44.     use IlluminateNotificationsNotifiable;
  45.     use IlluminateFoundationAuthUser as Authenticatable;
  46.  
  47.     class User extends Authenticatable
  48.     {
  49.        //protected $guarded = [];
  50.        protected $primaryKey = 'id_user';
  51.        use Notifiable;
  52.  
  53.  
  54.         /**
  55.          * The attributes that are mass assignable.
  56.          *
  57.          * @var array
  58.          */
  59.         protected $fillable = [
  60.             'name', 'email', 'password',
  61.         ];
  62.  
  63.         /**
  64.          * The attributes that should be hidden for arrays.
  65.          *
  66.          * @var array
  67.          */
  68.         protected $hidden = [
  69.             'password'
  70.         ];
  71.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top