for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Turahe\Master\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Facades\Cache;
/**
* Class District.
*
* @property string city
* @property string name
* @mixin \Eloquent
*/
class District extends Model
{
* @var string
protected $table = 'tm_districts';
* @var string[]
protected $casts = [
'meta' => 'array',
];
* Bootstrap the model and its traits.
* Caching model when updating and
* delete cache when delete models
* @return void
protected static function boot()
parent::boot(); // TODO: Change the autogenerated stub
static::updating(function ($instance) {
Cache::put('districts.'.$instance->slug, $instance);
});
static::deleting(function ($instance) {
Cache::delete('districts.'.$instance->slug);
}
* @return BelongsTo
public function city(): BelongsTo
return $this->belongsTo(City::class, 'city_id');
* @return HasMany
public function villages(): HasMany
return $this->hasMany(Village::class, 'district_id');
* @return mixed
public function getCityNameAttribute()
return $this->city->name;
public function getProvinceNameAttribute()
return $this->city->province->name;
province
Turahe\Master\Models\City
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.
* @return string
public function getAddressAttribute(): string
return sprintf(
'%s, %s, %s, Indonesia',
$this->name,
$this->city->name,
$this->city->province->name
);
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.