Level 1
returned $tenant->admin instead of $tenant. works now
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
This works fine locally. Register tenant -> redirect to tenant login page. When i clone this to a digital ocean server stops redirecting me and give me this error :c Controller
<?php
namespace App\Http\Controllers\Auth;
use App\Tenant;
use App\Providers\RouteServiceProvider;
use Illuminate\Support\Facades\Artisan;
use App\Console\Commands\CreateTenant;
use App\User;
use Spatie\Permission\Traits\HasRoles;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
{
/*
|--------------------------------------------------------------------------
| Register Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users as well as their
| validation and creation. By default this controller uses a trait to
| provide this functionality without requiring any additional code.
|
*/
use RegistersUsers, HasRoles;
/**
* Where to redirect users after registration.
*
* @var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
$this->middleware('guest');
}
/**
* Get a validator for an incoming registration request.
*
* @param array $data
* @return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
]);
}
/**
* Create a new user instance after a valid registration.
*
* @param array $data
* @return \App\User
*/
protected function create(array $data)
{
$subdomain = $data['subdomain'];
$name = $data['name'];
$email = $data['email'];
$password = $data['password'];
$phone = $data['phone'];
$doc = $data['doc'];
$zip = $data['address_zip'];
$address = $data['address'];
$number = $data['address_number'];
$comp = $data['address_comp'];
$district = $data['address_district'];
$city = $data['address_city'];
$state = $data['address_state'];
$company = $data['company'];
$tenant = $tenant = Tenant::registerTenant($name, $email, $password,$phone,$doc,$zip,$address,$number,$comp,$district,$city,$state, $subdomain, $company);
$this->redirectTo = 'http://' . $tenant->hostname->fqdn . '/login';
return $tenant;
}
}
Tenant Model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Hyn\Tenancy\Environment;
use Hyn\Tenancy\Models\Hostname;
use Hyn\Tenancy\Models\Website;
use Illuminate\Support\Facades\Hash;
use Hyn\Tenancy\Contracts\Repositories\HostnameRepository;
use Hyn\Tenancy\Contracts\Repositories\WebsiteRepository;
/**
* @property Website website
* @property Hostname hostname
* @property User admin
*/
class Tenant
{
public function __construct(Website $website = null, Hostname $hostname = null, User $admin = null)
{
$this->website = $website;
$this->hostname = $hostname;
$this->admin = $admin;
}
public static function delete($subdomain)
{
$baseUrl = config('tenancy.hostname.default');
$subdomain = "{$subdomain}.{$baseUrl}";
if ($tenant = Hostname::where('fqdn', $subdomain)->firstOrFail()) {
app(HostnameRepository::class)->delete($tenant, true);
app(WebsiteRepository::class)->delete($tenant->website, true);
return "Tenant {$subdomain} successfully deleted.";
}
}
public static function deleteByFqdn($fqdn)
{
if ($tenant = Hostname::where('fqdn', $fqdn)->firstOrFail()) {
app(HostnameRepository::class)->delete($tenant, true);
app(WebsiteRepository::class)->delete($tenant->website, true);
return "Tenant {$fqdn} successfully deleted.";
}
}
public static function registerTenant($name, $email, $password,$phone,$doc,$zip,$address,$number,$comp,$district,$city,$state, $subdomain, $company): Tenant
{
// Convert all to lowercase
$subdomain = strtolower($subdomain);
$email = strtolower($email);
$website = new Website;
app(WebsiteRepository::class)->create($website);
// associate the website with a hostname
$hostname = new Hostname;
$baseUrl = config('tenancy.hostname.default');
$hostname->fqdn = "{$subdomain}.{$baseUrl}";
app(HostnameRepository::class)->attach($hostname, $website);
// make hostname current
app(Environment::class)->tenant($hostname->website);
// Make the registered user the default Admin of the site.
$admin = static::makeAdmin($name, $email, $password,$phone,$doc,$zip,$address,$number,$comp,$district,$city,$state, $company);
return new Tenant($website, $hostname, $admin);
}
private static function makeAdmin($name, $email, $password,$phone,$doc,$zip,$address,$number,$comp,$district,$city,$state, $company): User
{
$admin = User::create(['name' => $name, 'email' => $email, 'password' => Hash::make($password), 'phone' => $phone,'address_zip' => $zip,'address' => $address,'address_number' => $number,'address_comp' => $comp,'address_city' => $city,'address_district' => $district,'address_state'=> $state, 'doc' => $doc, 'company' => $company]);
$admin->guard_name = 'web';
$admin->assignRole('Super Admin');
return $admin;
}
public static function tenantExists($subdomain)
{
$subdomain = $subdomain . '.' . config('tenancy.hostname.default');
return Hostname::where('fqdn', $subdomain)->exists();
}
}
Help pleasu
returned $tenant->admin instead of $tenant. works now
Please or to participate in this conversation.