Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace App;
- use IlluminateSupportFacadesDB;
- use IlluminateDatabaseEloquentModel;
- class Occurrence extends Model {
- protected $table = 'occurrences';
- protected $guarded = [];
- protected $primaryKey = 'id_occurrence';
- public function owner(){
- return $this->belongsTo(User::class, 'id_user_fk', 'id_user');
- }
- public function department(){
- return $this->belongsTo(Department::class, 'id_department_fk', 'id_department');
- }
- }
- $occurrence = new AppOccurrence;
- => AppOccurrence {#2938}
- >>> $occurrence->first()->owner;
- => AppUser {#2947
- id_user: 2,
- name: "Jiripoqueiro",
- email: "jiripoca_vaipiar@yahoo.com.br",
- dateofbirth: "1985-08-15",
- active: 1,
- created_at: "2019-06-03 12:05:50",
- updated_at: "2019-06-03 12:05:50",
- }
- >>> $occurrence = new AppOccurrence;
- => AppOccurrence {#2970}
- >>> $occurrence->first()->owner;
- => null
- namespace App;
- use IlluminateNotificationsNotifiable;
- use IlluminateFoundationAuthUser as Authenticatable;
- class User extends Authenticatable
- {
- //protected $guarded = [];
- protected $primaryKey = 'id_user';
- use Notifiable;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'name', 'email', 'password',
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password'
- ];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement