Lae/app/Models/Admin/Admin.php

38 lines
760 B
PHP
Raw Normal View History

2022-08-12 07:56:56 +00:00
<?php
namespace App\Models\Admin;
2022-08-12 08:10:45 +00:00
use Illuminate\Support\Str;
2022-08-12 07:56:56 +00:00
use Illuminate\Database\Eloquent\Model;
2022-08-12 08:10:45 +00:00
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Factories\HasFactory;
2022-08-12 07:56:56 +00:00
class Admin extends Model
{
2022-08-12 08:10:45 +00:00
use HasFactory, SoftDeletes;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password'
];
// protect password
public function setPasswordAttribute($value)
{
$this->attributes['password'] = bcrypt($value);
}
// before create admin, generate api_token
public static function boot()
{
parent::boot();
self::creating(function ($admin) {
$admin->api_token = Str::random(60);
});
}
2022-08-12 07:56:56 +00:00
}