Add root team + localhost (coolify host) in prod seeder
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Team;
|
||||
use App\Models\User;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Laravel\Fortify\Contracts\CreatesNewUsers;
|
||||
@@ -33,23 +34,38 @@ class CreateNewUser implements CreatesNewUsers
|
||||
'password' => $this->passwordRules(),
|
||||
])->validate();
|
||||
|
||||
$team = Team::create([
|
||||
'name' => explode(' ', $input['name'], 2)[0] . "'s Team",
|
||||
'personal_team' => true,
|
||||
]);
|
||||
|
||||
$user = User::create([
|
||||
'name' => $input['name'],
|
||||
'email' => $input['email'],
|
||||
'password' => Hash::make($input['password']),
|
||||
'is_root_user' => User::count() == 0 ? true : false,
|
||||
]);
|
||||
if (User::count() == 0) {
|
||||
// If this is the first user, make them the root user
|
||||
// Team is already created in the database/seeders/ProductionSeeder.php
|
||||
$team = Team::find(0);
|
||||
$user = User::create([
|
||||
'id' => 0,
|
||||
'name' => $input['name'],
|
||||
'email' => $input['email'],
|
||||
'password' => Hash::make($input['password']),
|
||||
'is_root_user' => true,
|
||||
]);
|
||||
} else {
|
||||
$team = Team::create([
|
||||
'name' => explode(' ', $input['name'], 2)[0] . "'s Team",
|
||||
'personal_team' => true,
|
||||
]);
|
||||
$user = User::create([
|
||||
'name' => $input['name'],
|
||||
'email' => $input['email'],
|
||||
'password' => Hash::make($input['password']),
|
||||
'is_root_user' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
// Add user to team
|
||||
DB::table('team_user')->insert([
|
||||
'user_id' => $user->id,
|
||||
'team_id' => $team->id,
|
||||
'role' => 'admin',
|
||||
]);
|
||||
|
||||
// Set session variable
|
||||
session(['currentTeam' => $user->currentTeam = $team]);
|
||||
return $user;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,11 @@ class HomeController extends Controller
|
||||
public function show()
|
||||
{
|
||||
$projects = session('currentTeam')->load(['projects'])->projects;
|
||||
return view('home', ['projects' => $projects]);
|
||||
$servers = session('currentTeam')->load(['servers'])->servers;
|
||||
|
||||
return view('home', [
|
||||
'servers' => $servers,
|
||||
'projects' => $projects
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ class Team extends BaseModel
|
||||
'personal_team' => 'boolean',
|
||||
];
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'personal_team'
|
||||
];
|
||||
|
||||
@@ -19,6 +19,7 @@ class User extends Authenticatable
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'id',
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
|
||||
Reference in New Issue
Block a user