Basic tenant structure
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
@@ -19,6 +20,11 @@ class AppServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
Auth::provider('tenant-users', function ($app, array $config) {
|
||||
return new TenantUserProvider(
|
||||
$app['hash'],
|
||||
$config['model']
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
26
app/Providers/InertiaProvider.php
Normal file
26
app/Providers/InertiaProvider.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Inertia\Inertia;
|
||||
use Inertia\Response;
|
||||
|
||||
final class InertiaProvider
|
||||
{
|
||||
private string $vueFile;
|
||||
private array $props;
|
||||
|
||||
public function __construct(string $vueFile, array $props) {
|
||||
$this->vueFile = $vueFile;
|
||||
$this->props = $props;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function render() : Response {
|
||||
return Inertia::render(
|
||||
str_replace('/', '/Views/', $this->vueFile),
|
||||
$this->props
|
||||
);
|
||||
}
|
||||
}
|
||||
23
app/Providers/TenantUserProvider.php
Normal file
23
app/Providers/TenantUserProvider.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Auth\EloquentUserProvider;
|
||||
|
||||
class TenantUserProvider extends EloquentUserProvider
|
||||
{
|
||||
public function retrieveByCredentials(array $credentials)
|
||||
{
|
||||
$query = $this->createModel()->newQuery();
|
||||
|
||||
foreach ($credentials as $key => $value) {
|
||||
if (! str_contains($key, 'password')) {
|
||||
$query->where($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$query->where('tenant', app('tenant')->slug);
|
||||
|
||||
return $query->first();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user