Я разрабатываю мультитенантное приложение laravel с использованием пакета HYN .
Пока все работает нормально, но когда я создаю арендатора через систему, мне приходится переключаться на окружение этого арендатора для добавления пользователя с правами администратора в указанную базу данных c.
Ниже показано, как я создаю клиента с конца системы.
SchoolController. php
public function createSchool(Request $request)
{
$validator = Validator::make($request->all(),[
'school_name' => 'required',
'school_address' => 'required',
'school_logo' => 'required|file',
'school_type' => 'required',
'school_sub_domain' => 'required',
'school_email' => 'required',
'school_default_password' => 'required',
'school_modules' => 'required|array'
]);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput();
}
$website = new Website;
$website->school_name = $request->school_name;
$website->school_address = $request->school_address;
//$website->school_logo = $request->school_logo;
$website->school_type = $request->school_type;
$website->school_email = $request->school_email;
$website->school_default_password = $request->school_default_password;
$school_logo = $request->file('school_logo');
$allowed_file_extentions = [
'jpeg',
'png',
'jpg',
'gif',
'svg'
];
if (false == in_array($school_logo->getClientOriginalExtension(), $allowed_file_extentions)) {
return back()->withErrors(['school_logo'=>'Allowed file types are jpeg,png,jpg,gif and svg']);
}
$website->school_logo = 'NOT_SET';
app(WebsiteRepository::class)->create($website);
$logo_path = $website->uuid.'/logo/' . time() . '.' . $school_logo->getClientOriginalExtension();
$t = Storage::disk('tenant')->put($logo_path, file_get_contents($school_logo), 'public');
$website->school_logo = $logo_path;
$website->save();
//creating hostname
$hostname = new Hostname;
$hostname->fqdn = $request->school_sub_domain.'.'.config('app.app_fqdn');
app(HostnameRepository::class)->create($hostname);
app(HostnameRepository::class)->attach($hostname, $website);
$school_modules = $request->school_modules;
$school_modules_to_create = [];
foreach($school_modules as $key => $value){
array_push($school_modules_to_create,[
'website_id' => $website->id,
'module_id' => $value
]);
}
WebsiteModule::insert($school_modules_to_create); // System model
//Switching to tenant environment to seed super admin for the tenant
$tenancy = app(Environment::class);
$tenancy->hostname($hostname);
$tenancy->tenant($website);
$tenancy->tenant(); // resolves $website
$id = Staff::createSuperAdminFromSystem([
'email' => $request->school_email,
'password' => $request->school_default_password,
]);
return redirect()->route('system.add_module'); //Here I am getting issue.
}
web. php
Route::prefix('system')->group(function () {
Route::get('login', ['as' => 'system.login', 'uses' => 'System\AuthController@viewLogin']);
Route::post('login-validate', ['as' => 'system.login.validate', 'uses' => 'System\AuthController@loginValidate']);
Route::group(['middleware' => ['system.auth']], function () {
Route::get('dashboard', ['as' => 'system.dashboard', 'uses' => 'System\AuthController@viewDashboard']);
Route::get('logout', ['as' => 'system.logout', 'uses' => 'System\AuthController@doLogout']);
########### Sidebar routes ###############
Route::get('modules', ['as' => 'system.modules', 'uses' => 'System\ModuleController@viewModules']);
Route::get('add-module', ['as' => 'system.add_module', 'uses' => 'System\ModuleController@viewAddModule']);
Route::post('create-module', ['as' => 'system.create_module', 'uses' => 'System\ModuleController@createModule']);
Route::get('add-school',['as' => 'add.school', 'uses' => 'System\SchoolController@addSchool']);
Route::post('create-school',['as' => 'system.create.school', 'uses' => 'System\SchoolController@createSchool']);
});
});
Как видите, route('system.add_module')
- системный маршрут, и давайте предположим, что моя системная базовая ссылка - http://example.com
и, соответственно, меня перенаправят на http://example.com/system/add-module
, но меня направят на http://<tenant_hostname>.example.com/system/add-module
Пожалуйста, помогите мне в этом, поскольку документация весьма неоднозначна и трудна для понимания.