fixed routes and phone numbers in places list
This commit is contained in:
@@ -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;
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<td><a class="text-indigo-600 hover:text-indigo-900 transition-colors"
|
||||
href="{{ $place->url }}">{{ $place->name }}</a></td>
|
||||
<td>{{ $place->address ?? '—' }}</td>
|
||||
<td>{{ $place->phone }}</td>
|
||||
<td>{{ $place->formattedPhone }}</td>
|
||||
<td class="text-center">
|
||||
<a href="#" title="Показать на карте"
|
||||
class="text-gray-500 hover:text-blue-600 transition-colors flex items-center justify-center"
|
||||
|
||||
+1
-1
@@ -15,10 +15,10 @@ use App\Http\Controllers\VkBotController;
|
||||
|
||||
Route::middleware('auth')
|
||||
->group(function () {
|
||||
Route::get('/places/create', [PlacesController::class, 'create'])->name('places.create');
|
||||
Route::get('/places', [PlacesController::class, 'index'])->name('places.index');
|
||||
Route::get('/places/{id}', [PlacesController::class, 'edit'])->name('places.edit');
|
||||
Route::put('/places/{id}', [PlacesController::class, 'update'])->name('places.update');
|
||||
Route::get('/places/create', [PlacesController::class, 'create'])->name('places.create');
|
||||
Route::post('/places/store', [PlacesController::class, 'store'])->name('places.store');
|
||||
Route::delete('/places/{id}', [PlacesController::class, 'delete'])->name('places.delete');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user