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: docs/6.x/extend/http.md
+17-9Lines changed: 17 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,9 +9,9 @@ Controllers are not automatically discovered or given routes in Craft 6.x, so yo
9
9
10
10
As your plugin is booted, the `CraftCms\Cms\Plugin\Concerns\HasRoutes` concern looks for three files in your plugin’s top-level `routes/` directory, each with a distinct behavior:
11
11
12
-
-`web.php` — Front-end routes, with standard middleware (`craft` and `craft.web`).
12
+
-`web.php` — Front-end routes, with standard [middleware](#middleware) (`craft` and `craft.web`).
13
13
-`cp.php` — Control panel routes, with additional middleware (`craft.cp`) that automatically enforces basic permissions. These routes are prefixed with your `cpTrigger`.
14
-
-`actions.php` — A compatibility layer for Yii’s “action path” routing scheme. These routes are registered twice: once prefixed with your `actionTrigger` using standard middleware, and once prefixed with `{cpTrigger}/{actionTrigger}` using the additional control panel middleware.
14
+
-`actions.php` — A compatibility layer for Yii’s [action path](#action-paths) routing scheme. These routes are registered twice: once prefixed with the project’s `actionTrigger` using standard middleware, and once prefixed with `{cpTrigger}/{actionTrigger}` using the additional control panel middleware. Your plugin’s handle is also inserted between these prefixes and the declared routes.
15
15
16
16
Here’s an example of a `web.php` file:
17
17
@@ -35,7 +35,7 @@ This is similar to how Craft has required each project to choose where its Graph
35
35
:::
36
36
37
37
Yii’s automatic routing scheme for controller actions used specific paths that involved the plugin or module’s identifier and kebab-cased controller and action names.
38
-
Craft 6.x does not impose any of these requirements—but continuing to prefix routes with your plugin handle is a great way to avoid collisions.
38
+
Craft 6.x does not impose any of these requirements for routes defined in `web.php` or `cp.php`—but continuing to prefix routes with your plugin handle is a great way to avoid collisions.
39
39
40
40
## Action Paths
41
41
@@ -44,17 +44,20 @@ Plugins can define a special `routes/actions.php` file to maintain compatibility
44
44
```php
45
45
# routes/actions.php
46
46
47
-
Route::prefix('activity', function() {
48
-
Route::post('events/log', TrackEvent::class);
49
-
});
47
+
Route::post('events/track', TrackEvent::class);
50
48
51
49
# Two routes:
52
-
# -> actions/activity/events/log
53
-
# -> admin/actions/activity/events/log
50
+
# -> actions/activity/events/track
51
+
# -> admin/actions/activity/events/track
54
52
```
55
53
54
+
Action routes are automatically prefixed with your plugin’s handle (`activity`, in this example).
56
55
See the [Guest Entries](repo:craftcms/guest-entries/tree/5.x) plugin for an example.
57
56
57
+
::: warning
58
+
Action routes are considered a legacy feature, and while they are fully supported (even without the adapter), we encourage plugins to move to standard Laravel routing in `routes/web.php` and `routes/cp.php`
59
+
:::
60
+
58
61
## Middleware
59
62
60
63
All of Craft’s middleware is registered by `CraftCms\Cms\Route\RouteServiceProvider`.
@@ -206,7 +209,7 @@ In some situations, you may still need to resolve permissions directly via a use
A complete example of this kind of configurable routing can be found in our [Guest Entries](https://github.com/craftcms/guest-entries/tree/5.x) plugin.
271
274
275
+
::: warning
276
+
Individual projects can always add routes to your controllers that fully or selectively bypass middleware you would normally include.
277
+
:::
278
+
272
279
## Named Routes
273
280
274
281
If your route map is growing or changing frequently in development, you can give your routes [names](laravel:routing#named-routes) to avoid form actions, redirects, and routes from getting out of sync.
282
+
This can also help when making some portion of your plugin-provided routes customizable on a per-project basis, while retaining
Copy file name to clipboardExpand all lines: docs/6.x/extend/session.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ The session is deeply integrated with validation, templating, controllers, and a
4
4
5
5
## Auth
6
6
7
-
You can always get the current `User` element with `Illuminate\Support\Facades\Auth::user()`.
7
+
You can always get the current `User` element with `Illuminate\Support\Facades\Auth::craftUser()`.
8
8
Users are largely unchanged, but the class has been relocated to `CraftCms\Cms\User\Elements\User` and some of its functionality has been split out into concerns (or is handled entirely by Laravel).
0 commit comments