refactor: replace guarded and appends properties with attributes in models for improved clarity and consistency
This commit is contained in:
parent
b69f42ed31
commit
431bd1c0c2
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
@ -11,12 +12,11 @@
|
|||||||
use Spatie\Sluggable\HasSlug;
|
use Spatie\Sluggable\HasSlug;
|
||||||
use Spatie\Sluggable\SlugOptions;
|
use Spatie\Sluggable\SlugOptions;
|
||||||
|
|
||||||
|
#[Guarded(['id'])]
|
||||||
class Category extends Model
|
class Category extends Model
|
||||||
{
|
{
|
||||||
use HasFactory, HasSlug, SoftDeletes;
|
use HasFactory, HasSlug, SoftDeletes;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
@ -10,14 +12,12 @@
|
|||||||
use Spatie\MediaLibrary\HasMedia;
|
use Spatie\MediaLibrary\HasMedia;
|
||||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||||
|
|
||||||
|
#[Guarded(['id'])]
|
||||||
|
#[Appends(['proof_url'])]
|
||||||
class Expense extends Model implements HasMedia
|
class Expense extends Model implements HasMedia
|
||||||
{
|
{
|
||||||
use HasFactory, InteractsWithMedia, SoftDeletes;
|
use HasFactory, InteractsWithMedia, SoftDeletes;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
|
||||||
|
|
||||||
protected $appends = ['proof_url'];
|
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Scope;
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
use Illuminate\Database\Eloquent\Builder;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
@ -15,17 +17,12 @@
|
|||||||
use Spatie\Sluggable\HasSlug;
|
use Spatie\Sluggable\HasSlug;
|
||||||
use Spatie\Sluggable\SlugOptions;
|
use Spatie\Sluggable\SlugOptions;
|
||||||
|
|
||||||
|
#[Guarded(['id'])]
|
||||||
|
#[Appends(['thumbnail_url', 'images_data'])]
|
||||||
class Product extends Model implements HasMedia
|
class Product extends Model implements HasMedia
|
||||||
{
|
{
|
||||||
use HasFactory, HasSlug, InteractsWithMedia, SoftDeletes;
|
use HasFactory, HasSlug, InteractsWithMedia, SoftDeletes;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
|
||||||
|
|
||||||
protected $appends = [
|
|
||||||
'thumbnail_url',
|
|
||||||
'images_data',
|
|
||||||
];
|
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
@ -77,13 +74,13 @@ protected function imagesData(): Attribute
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function prices(): HasMany
|
|
||||||
{
|
|
||||||
return $this->hasMany(ProductPrice::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function categories(): BelongsToMany
|
public function categories(): BelongsToMany
|
||||||
{
|
{
|
||||||
return $this->belongsToMany(Category::class);
|
return $this->belongsToMany(Category::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function prices(): HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(ProductPrice::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,13 +3,13 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
use App\Enums\PriceType;
|
use App\Enums\PriceType;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
|
||||||
|
#[Guarded(['id'])]
|
||||||
class ProductPrice extends Model
|
class ProductPrice extends Model
|
||||||
{
|
{
|
||||||
protected $guarded = ['id'];
|
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -3,6 +3,8 @@
|
|||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Appends;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
@ -16,12 +18,11 @@
|
|||||||
|
|
||||||
#[Guarded('id')]
|
#[Guarded('id')]
|
||||||
#[Hidden(['password'])]
|
#[Hidden(['password'])]
|
||||||
|
#[Appends(['name'])]
|
||||||
class User extends Authenticatable
|
class User extends Authenticatable
|
||||||
{
|
{
|
||||||
use HasFactory, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
|
use HasFactory, Notifiable, SoftDeletes, TwoFactorAuthenticatable;
|
||||||
|
|
||||||
protected $appends = ['name'];
|
|
||||||
|
|
||||||
protected function casts(): array
|
protected function casts(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
|
|||||||
@ -2,17 +2,17 @@
|
|||||||
|
|
||||||
namespace App\Models;
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Guarded;
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
|
|
||||||
|
#[Guarded(['id'])]
|
||||||
class UserProfile extends Model
|
class UserProfile extends Model
|
||||||
{
|
{
|
||||||
use HasFactory, SoftDeletes;
|
use HasFactory, SoftDeletes;
|
||||||
|
|
||||||
protected $guarded = ['id'];
|
|
||||||
|
|
||||||
public function user(): BelongsTo
|
public function user(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class);
|
return $this->belongsTo(User::class);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user