Files
cheerstothe_season_2.0/app/Models/ManageRestaurant.php
sayliraut dff7e97057 change
2024-05-30 17:05:09 +05:30

43 lines
1.0 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Model;
class ManageRestaurant extends Model
{
use SoftDeletes;
use HasFactory;
protected $table = 'manage_restaurants';
protected $fillable = [
'short_id', 'name', 'description', 'restaurant_id', 'address', 'image', 'bio',
'try_on_1', 'try_on_2', 'try_on_3', 'try_on_4', 'exclusion', 'latitude', 'longitude',
'is_active', 'created_by', 'modified_by'
];
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
if (empty($model->short_id)) {
$model->short_id = static::generateUniqueShortId();
}
});
}
protected static function generateUniqueShortId()
{
do {
$shortId = Str::random(4);
} while (static::where('short_id', $shortId)->exists());
return $shortId;
}
}