# Роуты

Для удобства все роуты админки можно вынести в отдельный файл admin.php и подключить его в RouteServiceProvider.php.

```php
// app/Providers/RouteServiceProvider.php

Route::middleware(['web', 'auth'])
    ->group(base_path('routes/admin.php'));
```

Для каждого нового ресурса нужно создать 3 роута:

* страница вывода списка ресурсов
* страница редактирования ресурса
* страница создания ресурса

Каждому роуту нужно дать имя, оно будет использоваться кнопками управления ресурсом.

Также в роутах создания и редактирования нужно передать Eloquent модель в переменной model.&#x20;

Ниже пример файла для раздела с новостями.

```php
// routes/admin.php

<?php

use App\Models\Post;
use Illuminate\Support\Facades\Route;

Route::get('/admin/posts', function () {
    return view('admin.posts.list');
})->name('posts.list');

Route::get('/admin/posts/{post}/edit', function (Post $post) {
    return view('admin.posts.edit')
        ->with([
            'model' => $post
        ]);
})->name('posts.edit');

Route::get('/admin/posts/create', function () {
    return view('admin.posts.create')
        ->with([
            'model' => new Post()
        ]);
})->name('posts.create');

```

Если после авторизации в админке не работает редирект на главную страницу /admin, то в RouteServiceProvider.php измените константу HOME.

```php
// app/Providers/RouteServiceProvider.php

public const HOME = '/admin';
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://web-vovan.gitbook.io/rock-cms/nastroika/routy.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
