fixed routes and phone numbers in places list

This commit is contained in:
2026-06-17 08:23:54 +00:00
parent 3a7e8c30ac
commit 23b5b4a9b2
3 changed files with 26 additions and 2 deletions
+24
View File
@@ -4,6 +4,7 @@ namespace App\Models\ORM;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Casts\Attribute;
class Place extends Model
{
@@ -19,4 +20,27 @@ class Place extends Model
protected $fillable = [
'name','gps', 'phone', 'description', 'url', 'address'
];
protected function formattedPhone(): Attribute
{
return Attribute::make(
get: function () {
// Берем оригинальное значение из базы (например: 79991110101)
$phone = $this->phone;
// Если номер начинается с 8 или 7 и в нем 11 цифр
if (strlen($phone) === 11) {
return '+7 (' . substr($phone, 1, 3) . ') ' . substr($phone, 4, 3) . '-' . substr($phone, 7, 2) . '-' . substr($phone, 9, 2);
}
// Если номер записан без семерки (всего 10 цифр, например: 9991110101)
if (strlen($phone) === 10) {
return '+7 (' . substr($phone, 0, 3) . ') ' . substr($phone, 3, 3) . '-' . substr($phone, 6, 2) . '-' . substr($phone, 8, 2);
}
// Если формат странный (например, городской короткий), выводим как есть
return $phone;
}
);
}
}