Viewing File: /home/ubuntu/route-and-root-backend-base/app/Models/Country.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Country extends Model
{
use HasFactory;
protected $hidden = ['id','unique_id'];
protected $appends = ['country_id', 'country_unique_id'];
protected $guarded = ['id'];
public function getCountryIdAttribute() {
return $this->id;
}
public function getCountryUniqueIdAttribute() {
return $this->unique_id;
}
public function scopeApproved($query) {
return $query->where('status', APPROVED);
}
public static function boot() {
parent::boot();
static::creating(function ($model) {
$model->attributes['unique_id'] = "CS-".uniqid();
});
static::created(function($model) {
$model->attributes['unique_id'] = "CS-".$model->attributes['id']."-".uniqid();
$model->save();
});
static::updating(function ($model) {
});
static::deleting(function ($model) {
});
}
}
Back to Directory
File Manager