camya
camya
FFilament
Created by Phuc Le on 3/31/2024 in #❓┊help
Multi tenancy with multiple database support
I made it work kind of. Works for a first test. Ideas to optimize it are welcome. Tenant assets are now public available on https://sport.my-site.test/tenant/post/123.png I create the folders & public symlinks in CreateFrameworkDirectoriesForTenant
# config/tenancy.php
'filesystem' => [
'suffix_base' => 'tenant/',
]
# config/tenancy.php
'filesystem' => [
'suffix_base' => 'tenant/',
]
<?php

namespace App\Jobs;

class CreateFrameworkDirectoriesForTenant
{
protected $tenant;

public function __construct(Tenant $tenant)
{
$this->tenant = $tenant;
}

public function handle()
{
$this->tenant->run(function ($tenant) {
$storage_path = storage_path();

$suffixBase = config('tenancy.filesystem.suffix_base');

if (!is_dir(public_path($suffixBase))) {
@mkdir(public_path($suffixBase), 0777, true);
}

if (!is_dir($storage_path)) {
@mkdir("{$storage_path}/app/public", 0777, true);
@mkdir("{$storage_path}/framework/cache", 0777, true);

symlink("{$storage_path}/app/public", public_path("{$suffixBase}{$tenant->id}"));
}
});
}
}
<?php

namespace App\Jobs;

class CreateFrameworkDirectoriesForTenant
{
protected $tenant;

public function __construct(Tenant $tenant)
{
$this->tenant = $tenant;
}

public function handle()
{
$this->tenant->run(function ($tenant) {
$storage_path = storage_path();

$suffixBase = config('tenancy.filesystem.suffix_base');

if (!is_dir(public_path($suffixBase))) {
@mkdir(public_path($suffixBase), 0777, true);
}

if (!is_dir($storage_path)) {
@mkdir("{$storage_path}/app/public", 0777, true);
@mkdir("{$storage_path}/framework/cache", 0777, true);

symlink("{$storage_path}/app/public", public_path("{$suffixBase}{$tenant->id}"));
}
});
}
}
Added to...
Events\TenantCreated::class => [
JobPipeline::make([
CreateFrameworkDirectoriesForTenant::class,
])
],
Events\TenantCreated::class => [
JobPipeline::make([
CreateFrameworkDirectoriesForTenant::class,
])
],
In the custom route FileUrlMiddleware, i update the filesystems.disks.public.url config value.
use App\Http\Middleware\FileUrlMiddleware;

->withMiddleware(function (Middleware $middleware) {
$middleware->group('universal', [
FileUrlMiddleware::class
]);
})
use App\Http\Middleware\FileUrlMiddleware;

->withMiddleware(function (Middleware $middleware) {
$middleware->group('universal', [
FileUrlMiddleware::class
]);
})
<?php
namespace App\Http\Middleware;

class FileUrlMiddleware
{
public function handle(Request $request, Closure $next): Response
{
config()->set(
'filesystems.disks.public.url',
url('/' . config('tenancy.filesystem.suffix_base') . tenant('id'))
);

return $next($request);
}
}
<?php
namespace App\Http\Middleware;

class FileUrlMiddleware
{
public function handle(Request $request, Closure $next): Response
{
config()->set(
'filesystems.disks.public.url',
url('/' . config('tenancy.filesystem.suffix_base') . tenant('id'))
);

return $next($request);
}
}
44 replies
FFilament
Created by Phuc Le on 3/31/2024 in #❓┊help
Multi tenancy with multiple database support
Hm, I have to wait for the v4 release than. Looks like symlinking the storage/tenant folders is also a challenge in v3. artisan storage:link does not work out of the box. Also this needs the tenancy.filesystem.url_override parameter too in order to set the correct url, i guess.
44 replies
FFilament
Created by Phuc Le on 3/31/2024 in #❓┊help
Multi tenancy with multiple database support
These are my settings. Still using the v3.8.3 of stancl/tenancy. 'filesystem' => [ 'suffix_base' => 'tenant', 'disks' => [ 'local', 'public', ], 'root_override' => [ 'local' => '%storage_path%/app/', 'public' => '%storage_path%/app/public/', ], 'suffix_storage_path' => true, 'asset_helper_tenancy' => false, ],
44 replies
FFilament
Created by Phuc Le on 3/31/2024 in #❓┊help
Multi tenancy with multiple database support
@Dennis Koch Great tips. I used the two links below to set up "tenancy for laravel". I still have a problem with the preview url in my Filament Form. The uploaded files are correctly saved in the folder /Development/valet/laravel-sites/filament-demo/storage/tenantsport/post/01HY2S9NP685FD3TFBCXRAF7RF.png. Great. The problem is that the preview in Filament is still loading from https://sport.my-site.test/storage/post/01HY2S9NP685FD3TFBCXRAF7RF.png when it should be https://sport.my-site.test/storage/tenantsport/post/01HY2S9NP685FD3TFBCXRAF7RF.png. Do you have any idea what I am missing here? Tenancy for Laravel - Livewire: https://tenancyforlaravel.com/docs/v3/integrations/livewire/#livewire Tenancy for Laravel - Universal Routes: https://tenancyforlaravel.com/docs/v3/features/universal-routes
44 replies
FFilament
Created by Phuc Le on 3/31/2024 in #❓┊help
Multi tenancy with multiple database support
Hi Dennis, great that you've got it working. I am suffering with stancl/tenancy and Filament at the moment. (I use Filament Form and Table separately). In stancl/tenancy the config "asset_helper_tenancy" is set to true. - Filament styles/scripts - Loaded from the wrong folder:
"@FilamentStyles and @FilamentScripts load files from the /tenancy/ folder, which does not work. (e.g. "/tenancy/assets/js/filament/support/async-alpine.js?v=3.2.80.0") - If I set asset_helper_tenancy = false it works. - FileUpload: File uploads are not saved to the subfolder of the tenancy folder (e.g. /storage/tenantsport/), so preview does not work. The tenancy folder (public disk) is set by stancl/tenancy to /Development/valet/laravel-sites/filament-demo/storage/tenantsport/app/public/, but files are saved to /Development/valet/laravel-sites/filament-demo/storage/app/public/ by the Filament FileUpload. It looks like Filament is not using the filesystems.disks.public.root configuration value when saving the file. I hope you can give me some ideas on how to make it work. Are there changes in v4-alpha, which makes it more easy to use stancl/tenancy and Filament together?
44 replies
FFilament
Created by camya on 4/30/2024 in #❓┊help
Table: sortable() with counts() - Set initial orderBy "desc" possible?
Your modifyQueryUsing() orders the table initally, but this is not what i need. 1. Initially the table is only ordered by title. (This works) 2. Than, the user clicks on sort "comment count". Now the count should be sorted "desc" on first click. I'm searching for a solution for 2. (Setting the initial sort direction to for a sortable field) At the moment, the first "sort" click has always orderBy "asc" by default. I my example, the generated SQL is the following on first click (order by "comments_count" asc). This is the current default behavior of sortable fields.
select "contributions".*, (select count(*) from "comments" where "contributions"."id" = "comments"."contribution_id") as "comments_count" from "contributions" order by "comments_count" asc limit 10 offset 0
select "contributions".*, (select count(*) from "comments" where "contributions"."id" = "comments"."contribution_id") as "comments_count" from "contributions" order by "comments_count" asc limit 10 offset 0
... but i want this (order by "comments_count" desc) on first click:
select "contributions".*, (select count(*) from "comments" where "contributions"."id" = "comments"."contribution_id") as "comments_count" from "contributions" order by "comments_count" desc limit 10 offset 0
select "contributions".*, (select count(*) from "comments" where "contributions"."id" = "comments"."contribution_id") as "comments_count" from "contributions" order by "comments_count" desc limit 10 offset 0
5 replies
FFilament
Created by camya on 4/30/2024 in #❓┊help
Table: sortable() with counts() - Set initial orderBy "desc" possible?
My posts table is initially orderdBy title. This works fine using $table->defaultSort('title'). The problem is the default orderBy for the sortable field "comment_count". It's default set to "asc" (e.g. from 0 comments -> Most comments). I can't figure out, how to set it to "desc" as inital order direction. (e.g. from Most comments -> 0 comments) Because of this, I have to click the sort button two times in order to sort it into the preferred direction. ("desc", e.g. from Most comments -> 0 comments)
5 replies
FFilament
Created by camya on 4/27/2024 in #❓┊help
Notification ->body('Some **bold** info') -- Markdown not parsed in V3
7 replies
FFilament
Created by camya on 4/27/2024 in #❓┊help
Notification ->body('Some **bold** info') -- Markdown not parsed in V3
Great Dennis, thank you for the hint. This works for me.... Notification::make()->body(str('Updated **post** 123')->markdown())->send(); Maye you can add this info to the V3 docs too. Also, thank you, @PovilasKorop . I really appreciate your Laravel content. 🙂
7 replies