first
This commit is contained in:
45
app/Models/Brand.php
Normal file
45
app/Models/Brand.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
/**
|
||||
* @property int $id
|
||||
* @property string $name
|
||||
* @property string $image
|
||||
* @property boolean $active
|
||||
* @property \Illuminate\Support\Facades\Date $created_at
|
||||
* @property \Illuminate\Support\Facades\Date $updated_at
|
||||
*/
|
||||
class Brand extends Model
|
||||
{
|
||||
/**
|
||||
* Casts
|
||||
* @var array<string, string>
|
||||
*/
|
||||
protected $casts = [
|
||||
'active' => 'boolean',
|
||||
];
|
||||
|
||||
/**
|
||||
* Booted
|
||||
*/
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::deleted(function ($model) {
|
||||
if ($model->image) {
|
||||
Storage::disk('public')->delete($model->image);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Image url
|
||||
*/
|
||||
public function imageUrl(): string
|
||||
{
|
||||
return url('/storage/' . $this->image);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user