-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #183 from ploi-deploy/feature/users-projects
Ability to add a project to a user via the user resource
- Loading branch information
Showing
4 changed files
with
64 additions
and
2 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
58 changes: 58 additions & 0 deletions
58
app/Filament/Resources/UserResource/RelationManagers/ProjectsRelationManager.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,58 @@ | ||
<?php | ||
|
||
namespace App\Filament\Resources\UserResource\RelationManagers; | ||
|
||
use App\Models\Project; | ||
use Filament\Forms; | ||
use Filament\Resources\Form; | ||
use Filament\Resources\RelationManagers\RelationManager; | ||
use Filament\Resources\Table; | ||
use Filament\Tables; | ||
use Illuminate\Database\Eloquent\Builder; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class ProjectsRelationManager extends RelationManager | ||
{ | ||
protected static string $relationship = 'projects'; | ||
|
||
protected static ?string $recordTitleAttribute = 'title'; | ||
|
||
public static function canViewForRecord(Model $ownerRecord): bool | ||
{ | ||
return Project::query()->where('private', '=', true)->count() > 0; | ||
} | ||
|
||
public static function form(Form $form): Form | ||
{ | ||
return $form | ||
->schema([ | ||
Forms\Components\TextInput::make('name') | ||
->required() | ||
->maxLength(255), | ||
]); | ||
} | ||
|
||
public static function table(Table $table): Table | ||
{ | ||
return $table | ||
->columns([ | ||
Tables\Columns\TextColumn::make('title'), | ||
]) | ||
->filters([ | ||
// | ||
]) | ||
->headerActions([ | ||
Tables\Actions\AttachAction::make() | ||
->recordSelectOptionsQuery(fn (Builder $query): Builder => $query->where('private', '=', true)) | ||
->recordSelect(fn (Forms\Components\Select $select) => $select->helperText(__('projects.select-hidden-projects'))) | ||
->inverseRelationshipName('members') | ||
->preloadRecordSelect(), | ||
]) | ||
->actions([ | ||
Tables\Actions\DetachAction::make(), | ||
]) | ||
->bulkActions([ | ||
Tables\Actions\DetachBulkAction::make(), | ||
]); | ||
} | ||
} |
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