Skip to content

Commit 51a5ad1

Browse files
committed
Handful of changes for alpha.6
1 parent 4115d33 commit 51a5ad1

2 files changed

Lines changed: 18 additions & 10 deletions

File tree

docs/6.x/extend/http.md

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ Controllers are not automatically discovered or given routes in Craft 6.x, so yo
99

1010
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:
1111

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`).
1313
- `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.
1515

1616
Here’s an example of a `web.php` file:
1717

@@ -35,7 +35,7 @@ This is similar to how Craft has required each project to choose where its Graph
3535
:::
3636

3737
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.
3939

4040
## Action Paths
4141

@@ -44,17 +44,20 @@ Plugins can define a special `routes/actions.php` file to maintain compatibility
4444
```php
4545
# routes/actions.php
4646

47-
Route::prefix('activity', function() {
48-
Route::post('events/log', TrackEvent::class);
49-
});
47+
Route::post('events/track', TrackEvent::class);
5048

5149
# Two routes:
52-
# -> actions/activity/events/log
53-
# -> admin/actions/activity/events/log
50+
# -> actions/activity/events/track
51+
# -> admin/actions/activity/events/track
5452
```
5553

54+
Action routes are automatically prefixed with your plugin’s handle (`activity`, in this example).
5655
See the [Guest Entries](repo:craftcms/guest-entries/tree/5.x) plugin for an example.
5756

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+
5861
## Middleware
5962

6063
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
206209

207210
```php
208211
// Check against the current user:
209-
Auth::user()->can('triggerReport');
212+
Auth::craftUser()->can('triggerReport');
210213

211214
// Check against a specific user:
212215
$recipient->can('requestAccess', $report);
@@ -269,9 +272,14 @@ Route::middleware(['throttle:activity'])->group(function () {
269272

270273
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.
271274

275+
::: warning
276+
Individual projects can always add routes to your controllers that fully or selectively bypass middleware you would normally include.
277+
:::
278+
272279
## Named Routes
273280

274281
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
275283

276284
## Helpers
277285

docs/6.x/extend/session.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The session is deeply integrated with validation, templating, controllers, and a
44

55
## Auth
66

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()`.
88
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).
99

1010
## Flashes

0 commit comments

Comments
 (0)