37 lines
905 B
PHP
37 lines
905 B
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Foundation\Validation\ValidatesRequests;
|
|
use Illuminate\Routing\Controller as BaseController;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
class Controller extends BaseController
|
|
{
|
|
use AuthorizesRequests, ValidatesRequests;
|
|
|
|
/**
|
|
* Get the current tenant ID from session or authenticated user.
|
|
* Falls back to the authenticated user's tenant_id if session is missing.
|
|
*/
|
|
protected function getTenantId(): ?int
|
|
{
|
|
$id = session('tenant_id');
|
|
|
|
if ($id) {
|
|
return (int) $id;
|
|
}
|
|
|
|
// Fallback: get from authenticated user
|
|
$user = Auth::user();
|
|
|
|
if ($user && $user->tenant_id) {
|
|
session(['tenant_id' => $user->tenant_id]);
|
|
return (int) $user->tenant_id;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|