You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: redirects.md
+26-22Lines changed: 26 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,24 @@
1
-
# HTTP Redirects
1
+
git 2a0615c0b2833c9a6c80052c6896071fa525d0fc
2
2
3
-
-[Creating Redirects](#creating-redirects)
4
-
-[Redirecting To Named Routes](#redirecting-named-routes)
5
-
-[Redirecting To Controller Actions](#redirecting-controller-actions)
6
-
-[Redirecting With Flashed Session Data](#redirecting-with-flashed-session-data)
3
+
---
4
+
5
+
# HTTP переадресация
6
+
7
+
-[Создание переадресации](#creating-redirects)
8
+
-[Переадресация на именованные маршруты](#redirecting-named-routes)
9
+
-[Переадресация на методы контроллера](#redirecting-controller-actions)
10
+
-[Переадресация с данными сеанса](#redirecting-with-flashed-session-data)
7
11
8
12
<aname="creating-redirects"></a>
9
-
## Creating Redirects
13
+
## Создание переадресации
10
14
11
-
Redirect responses are instances of the `Illuminate\Http\RedirectResponse`class, and contain the proper headers needed to redirect the user to another URL. There are several ways to generate a `RedirectResponse` instance. The simplest method is to use the global `redirect` helper:
15
+
Переадресация является экземпляром класса `Illuminate\Http\RedirectResponse`и содержит в ответе правильные заголовки, необходимые для перенаправления пользователя на другой URL. Есть несколько способов сгенерировать экземпляр `RedirectResponse`. Самый простой способ — использовать глобальный помощник `redirect`:
12
16
13
17
Route::get('/dashboard', function () {
14
18
return redirect('/home/dashboard');
15
19
});
16
20
17
-
Sometimes you may wish to redirect the user to their previous location, such as when a submitted form is invalid. You may do so by using the global`back` helper function. Since this feature utilizes the [session](/docs/{{version}}/session), make sure the route calling the `back` function is using the `web`middleware group or has all of the session middleware applied:
21
+
Иногда необходимо перенаправить пользователя в его предыдущее местоположение, например, когда отправленная форма недействительна. Это можно сделать с помощью глобальной вспомогательной функции`back`. Поскольку эта функция использует [сессии](/docs/{{version}}/session), убедитесь, что маршрут, вызывающий функцию `back`, использует группу посредников`web`или применяет все необходимые посредники сессии:
18
22
19
23
Route::post('/user/profile', function () {
20
24
// Validate the request...
@@ -23,31 +27,31 @@ Sometimes you may wish to redirect the user to their previous location, such as
23
27
});
24
28
25
29
<aname="redirecting-named-routes"></a>
26
-
## Redirecting To Named Routes
30
+
## Переадресация на именованные маршруты
27
31
28
-
When you call the`redirect`helper with no parameters, an instance of `Illuminate\Routing\Redirector` is returned, allowing you to call any method on the`Redirector` instance. For example, to generate a `RedirectResponse`to a named route, you may use the `route` method:
32
+
Когда вы вызываете помощник`redirect`без параметров, возвращается экземпляр `Illuminate\Routing\Redirector`, что позволяет вам вызывать любой метод в экземпляре`Redirector`. Например, чтобы сгенерировать `RedirectResponse`на именованный маршрут, вы можете использовать метод route:
29
33
30
34
return redirect()->route('login');
31
35
32
-
If your route has parameters, you may pass them as the second argument to the `route` method:
36
+
Если ваш маршрут имеет параметры, вы можете передать их в качестве второго аргумента методу `route`:
33
37
34
38
// For a route with the following URI: profile/{id}
If you are redirecting to a route with an "ID" parameter that is being populated from an Eloquent model, you may pass the model itself. The ID will be extracted automatically:
45
+
Если вы перенаправляете на маршрут с параметром "ID", который заполняется из модели Eloquent, вы можете передать саму модель. ID будет извлечен автоматически:
42
46
43
47
// For a route with the following URI: profile/{id}
44
48
45
49
return redirect()->route('profile', [$user]);
46
50
47
-
If you would like to customize the value that is placed in the route parameter, you should override the`getRouteKey`method on your Eloquent model:
51
+
Если вы хотите настроить значение, которое помещается в параметр маршрута, вы должны переопределить метод`getRouteKey`в вашей модели Eloquent:
48
52
49
53
/**
50
-
* Get the value of the model's route key.
54
+
* Получить значение ключа маршрута модели.
51
55
*
52
56
* @return mixed
53
57
*/
@@ -57,36 +61,36 @@ If you would like to customize the value that is placed in the route parameter,
57
61
}
58
62
59
63
<aname="redirecting-controller-actions"></a>
60
-
## Redirecting To Controller Actions
64
+
## Перенаправление на методы контроллера
61
65
62
-
You may also generate redirects to [controller actions](/docs/{{version}}/controllers). To do so, pass the controller and action name to the `action`method:
66
+
Вы также можете обеспечить перенаправления на [методы контроллера](/docs/{{version}}/controllers). Для этого передайте имя контроллера и его метода методу `action`экземпляра `redirect`:
Redirecting to a new URL and [flashing data to the session](/docs/{{version}}/session#flash-data)are usually done at the same time. Typically, this is done after successfully performing an action when you flash a success message to the session. For convenience, you may create a`RedirectResponse`instance and flash data to the session in a single, fluent method chain:
81
+
Перенаправление на новый URL-адрес и [передача данных в сеанс](/docs/{{version}}/session#flash-data)обычно выполняются одновременно. Обычно это делается после успешного выполнения действия, когда вы отправляете сообщение об успешном завершении сеанса. Для удобства вы можете создать экземпляр`RedirectResponse`и передать данные в сеанс в цепочке методов:
You may use the`withInput` method provided by the `RedirectResponse` instance to flash the current request's input data to the session before redirecting the user to a new location. Once the input has been flashed to the session, you may easily [retrieve it](/docs/{{version}}/requests#retrieving-old-input)during the next request:
89
+
Вы можете использовать метод`withInput`, предоставляемый экземпляром `RedirectResponse`, для передачи входных данных текущего запроса в сеанс перед перенаправлением пользователя на новый URL. После того как данные были переданы в сеанс, вы можете легко [получить их](/docs/{{version}}/requests#retrieving-old-input)во время следующего запроса:
86
90
87
91
return back()->withInput();
88
92
89
-
After the user is redirected, you may display the flashed message from the [session](/docs/{{version}}/session). For example, using [Blade syntax](/docs/{{version}}/blade):
93
+
После перенаправления вы можете отобразить всплывающее сообщение [сеанса](/docs/{{version}}/session). Например, используя [синтаксис Blade](/docs/{{version}}/blade):
0 commit comments