Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Livewire integration for Tenancy by path #206

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions source/docs/v3/integrations/livewire.blade.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ section: content

# Livewire {#livewire}

## Tenancy by domain

Open the `config/livewire.php` file and change this:

```php
Expand All @@ -29,3 +31,49 @@ Now you can use Livewire both in the central app and the tenant app.
Also make sure to enable [universal routes]({{ $page->link('features/universal-routes') }}).

And if you're using file uploads, read the [Real-time facades]({{ $page->link('realtime-facades') }}) page of the documentation. Livewire uses real-time facades in the uploading logic.

## Tenancy by path

Open the `config/livewire.php` file and change this:

```php
'middleware_group' => ['web'],
```

to this:

```php
'middleware_group' => [
'web',
InitializeTenancyByPath::class,
],
```

(Don't forget to import the middleware class.)

Open the `config/livewire.php` file and add this:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @andreasmatu pointed out in archtechx/tenancy#628 (comment), this should be something like routes/tenant.php:

Suggested change
Open the `config/livewire.php` file and add this:
Open the `routes/tenant.php` file and add this:


```php
use Livewire\Controllers\HttpConnectionHandler;

Route::group([
'prefix' => '/{tenant}',
'middleware' => [
'web',
InitializeTenancyByPath::class,
],
], function () {
Route::post('livewire/message/{name}', [HttpConnectionHandler::class, '__invoke']);
});
```

Finally, open the blade file where the `@@livewireScripts` directive is, and add:

```html
@@livewireScripts
<script>
window.livewire_app_url = '{{ tenant()->id }}';
stancl marked this conversation as resolved.
Show resolved Hide resolved
</script>
```

Now you can use Livewire both in the central app and the tenant app.