table with hotels

This commit is contained in:
2026-01-18 18:03:20 +00:00
parent ea511a00e6
commit 18aad4749f
16 changed files with 276 additions and 233 deletions

View File

@@ -8,70 +8,51 @@ use Illuminate\Http\Request;
class HotelController extends Controller
{
/**
* Показать список отелей.
*/
public function index()
{
$hotels = Hotel::all();
return response()->view('admin/hotels/index', compact('hotels'));
return view('admin.hotels.index', compact('hotels'));
}
/**
* Показать форму создания отеля.
*/
public function create()
{
return view('admin.hotels.create');
}
/**
* Сохранить новый отель.
*/
public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'address' => 'nullable|string',
'phone' => 'nullable|string',
'phone' => 'nullable|string|max:20',
]);
Hotel::create($validated);
return redirect()->route('admin.hotels.index')->with('success', 'Отель добавлен!');
return redirect()->route('admin.hotels.index')->with('success', 'Отель успешно добавлен!');
}
/**
* Показать форму редактирования отеля.
*/
public function edit(Hotel $hotel)
{
return view('admin.hotels.edit', compact('hotel'));
}
/**
* Обновить отель.
*/
public function update(Request $request, Hotel $hotel)
{
$validated = $request->validate([
'name' => 'required|string|max:255',
'address' => 'nullable|string',
'phone' => 'nullable|string',
'phone' => 'nullable|string|max:20',
]);
$hotel->update($validated);
return redirect()->route('admin.hotels.index')->with('success', 'Отель обновлён!');
return redirect()->route('admin.hotels.index')->with('success', 'Отель успешно обновлён!');
}
/**
* Удалить отель.
*/
public function destroy(Hotel $hotel)
{
$hotel->delete();
return redirect()->route('admin.hotels.index')->with('success', 'Отель удалён!');
return redirect()->route('admin.hotels.index')->with('success', 'Отель удалён.');
}
}
}