-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
484 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Staff; | ||
|
||
use App\Enums\GroupTypeEnum; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Group; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Gate; | ||
use Inertia\Inertia; | ||
|
||
class GroupTeamController extends Controller | ||
{ | ||
public function index(Group $group, Request $request) | ||
{ | ||
Gate::authorize('view', $group); | ||
$myDepartments = $request->user()->groups() | ||
->where('type', GroupTypeEnum::Department)->select('id', 'level')->get() | ||
->mapWithKeys(fn($role) => [$role->id => ucwords($role->level)]); | ||
return Inertia::render('Staff/Groups/Tabs/TeamTab', [ | ||
'group' => $group->loadCount('users')->only(['hashid', 'name', 'users_count','parent_id']), | ||
'parent' => $group->parent?->only(['hashid', 'name']), | ||
'teams' => $group->children() | ||
->where('type', GroupTypeEnum::Team) | ||
->withCount('users') | ||
->get(['hashid', 'name', 'users_count']), | ||
'myGroups' => $myDepartments->values(), | ||
'canEdit' => $group->isAdmin($request->user()) | ||
]); | ||
} | ||
|
||
public function store(Group $group, Request $request) | ||
{ | ||
Gate::authorize('update', $group); | ||
$validated = $request->validate([ | ||
'name' => 'required|string|max:255', | ||
]); | ||
$group->children()->create([ | ||
'name' => $validated['name'], | ||
'type' => GroupTypeEnum::Team, | ||
]); | ||
return redirect()->back(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
database/migrations/2024_08_14_000454_add_parent_id_to_groups_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
use App\Models\Group; | ||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::table('groups', function (Blueprint $table) { | ||
$table->foreignIdFor(Group::class, 'parent_id')->after('id')->nullable()->constrained('groups')->cascadeOnDelete(); | ||
}); | ||
} | ||
}; |
Oops, something went wrong.