Skip to content

Commit

Permalink
Merge pull request #88 from BRACKETS-by-TRIAD/feat/CRADEV-573-update-…
Browse files Browse the repository at this point in the history
…inertiajs-config-for-laravel-11

✨ feat: Updated 'Using InertiaJS outside Craftable PRO' for Laravel 11+
  • Loading branch information
strstensky authored May 21, 2024
2 parents 27e3e9e + d4b1e74 commit a008808
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions pages/getting-started/inertiajs-configuration.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,63 @@ return [

## Using InertiaJS outside Craftable PRO

### Laravel 11+

If you would like to use an InertiaJS in the frontend part of your application we recommend you to separate the Craftable PRO routes with it's own InertiaJS middleware.

<div className="steps-container">

### Extract routes

Move all `craftable-pro` routes from `routes/web.php` into a separate file `routes/craftable-pro.php`

```php filename="routes/craftable-pro.php" copy
<?php

use Illuminate\Support\Facades\Route;

Route::craftablePro('admin');
```

### Update `bootstrap/app.php`

Create a new route middleware group, with the same middlewares as you have in the web group:

```php filename="bootstrap/app.php" {5,10-13,18-25}
<?php
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Support\Facades\Route;

return Application::configure(basePath: dirname(__DIR__))
->withRouting(
web: __DIR__.'/../routes/web.php',
then: function () {
Route::middleware('craftable-pro')
->group(base_path('routes/craftable-pro.php'));
},
commands: __DIR__.'/../routes/console.php',
health: '/up',
)
->withMiddleware(function (Middleware $middleware) {
$middleware->appendToGroup('craftable-pro', [
\Illuminate\Cookie\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Illuminate\Foundation\Http\Middleware\ValidateCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
]);
})
->withExceptions(function (Exceptions $exceptions) {
...
```

</div>

### Older Laravel versions

If you would like to use an InertiaJS in the frontend part of your application we recommend you to separate the Craftable PRO routes with it's own InertiaJS middleware.

<div className="steps-container">
Expand Down

0 comments on commit a008808

Please sign in to comment.