12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- <?php
- namespace App\Models;
- use Illuminate\Contracts\Auth\MustVerifyEmail;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Foundation\Auth\User as Authenticatable;
- use Illuminate\Notifications\Notifiable;
- class User extends Authenticatable
- {
- use HasFactory, Notifiable;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- protected $fillable = [
- 'name',
- 'email',
- 'username',
- 'password',
- ];
- /**
- * The attributes that should be hidden for arrays.
- *
- * @var array
- */
- protected $hidden = [
- 'password',
- 'remember_token',
- ];
- /**
- * The attributes that should be cast to native types.
- *
- * @var array
- */
- protected $casts = [
- 'email_verified_at' => 'datetime',
- ];
- protected static function boot()
- {
- parent::boot();
- static::created(function ($user) {
- $user->profile()->create([
- 'title' => $user->username,
- ]);
- });
- }
- public function posts()
- {
- return $this->hasMany(Post::class)->orderBy('created_at', 'DESC');
- }
- public function following()
- {
- return $this->belongsToMany(Profile::class);
- }
- public function profile()
- {
- return $this->hasOne(Profile::class);
- }
- }
|