*/ protected $fillable = [ 'first_name', 'last_name', 'judging_preference', 'cell_phone', 'email', 'password', 'profile_image_url', 'school_id' ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } public function full_name(): string { return $this->first_name . ' ' . $this->last_name; } public function emailDomain(): string { $pos = strpos($this->email, '@'); return substr($this->email, $pos+1); } public function school(): BelongsTo { return $this->belongsTo(School::class); } /** * Return an array of schools using the users email domiain * @return SchoolEmailDomain[] */ public function possibleSchools() { if ($this->school_id) { $return[] = $this->school; return $return; } return SchoolEmailDomain::with('school')->where('domain','=',$this->emailDomain())->get(); // $x = SchoolEmailDomain::with('school')->where('domain','=',Auth::user()->emailDomain())->get(); // $possibilities = SchoolEmailDomain::with('school')->where('domain','=', $this->emailDomain())->getModels(); // $return = []; // foreach ($possibilities as $possibility) { // $return[] = $possibility->school; // } // return $return; } }