Mini Shell
<?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;
use Illuminate\Support\Facades\Storage;
use Laravel\Sanctum\HasApiTokens;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* Table name.
*
* @var string
*/
protected $table = 'user';
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
'job_type',
'image',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
/**
* Set the user's image.
*
* @param file $image
*/
public function setImageAttribute($image){
if($image){
if(gettype($image) === 'string'){
$this->attributes['image'] = $image;
}else{
$this->attributes['image'] = Storage::putFile('avatars', $image);
}
}else{
if(!$this->attributes['image']){
$this->attributes['image'] = 'https://gravatar.com/avatar/' . md5($this->attributes['email']) . '?s=200';
}
}
}
/**
* Get cards owned by the user.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function cardsOwned(){
return $this->hasMany(Card::class);
}
}
Zerion Mini Shell 1.0