schema([ Forms\Components\TextInput::make('title_ar') ->required() ->label(__('Title')) ->maxLength(255), Forms\Components\RichEditor::make('description_ar') ->required() ->label(__('Description')) ->columnSpanFull(), Forms\Components\Hidden::make('title_en') ->default(''), Forms\Components\Hidden::make('description_en') ->default(''), Forms\Components\Hidden::make('status') ->required() ->default('0'), Forms\Components\FileUpload::make('img') ->required() ->label(__('Img')) ->image() ->previewable(), Forms\Components\Hidden::make('user_id') ->default(function () { return Auth::id(); // Get the ID of the currently logged-in user }), ]); } else return $form->schema([ Forms\Components\TextInput::make('title_en') ->required() ->label(__('Title')) ->maxLength(255), Forms\Components\RichEditor::make('description_en') ->required() ->label(__('Description')) ->columnSpanFull(), Forms\Components\Hidden::make('title_ar') ->default(''), Forms\Components\Hidden::make('description_ar') ->default(''), Forms\Components\Hidden::make('status') ->required() ->default('0'), Forms\Components\FileUpload::make('img') ->required() ->previewable() ->label(__('Img')) // ->imageEditor() ->image(), Forms\Components\Hidden::make('user_id') ->default(function () { return Auth::id(); // Get the ID of the currently logged-in user }), ]); } public static function table(Table $table): Table { $currentLanguage = App::getLocale(); // $title = App::getLocale() === 'ar'? 'title_ar' : 'title_en'; if($currentLanguage === 'ar'){ $title = 'title_ar'; $query = Project::query()->whereNotNull('title_ar'); } else { $title = 'title_en'; $query = Project::query()->whereNotNull('title_en'); } return $table ->columns([ Tables\Columns\Layout\Stack::make([ Tables\Columns\ImageColumn::make('img') // ->circular(), ->columnSpanFull(), Tables\Columns\TextColumn::make($title) ->icon('heroicon-m-bookmark'), Tables\Columns\TextColumn::make('created_at') ->icon('heroicon-s-pencil-square'), Tables\Columns\ToggleColumn::make('status') ->disabled(), ]), ]) ->contentGrid([ 'md' => 2, 'xl' => 3, ]) ->filters([ // ]) ->actions([ Tables\Actions\ViewAction::make(), Tables\Actions\EditAction::make() ->successNotification( Notification::make() ->success() ->title(__('Project Updeted')) ->body(__('The Project has been updated successfully.'))), Tables\Actions\DeleteAction::make() ->before(function ($record, $action) { if($record->user_id!== Auth::id()){ Notification::make() ->title(__('Sorry')) ->body(__('You can not delete this project as it belongs to another user.')) ->status('danger') ->send(); $action->cancel(); } }) ->successNotification( Notification::make() ->success() ->title(__('Project Deleted')) ->body(__('The Project has been deleted successfully.'))), Tables\Actions\Action::make(__('Change Status')) ->icon('heroicon-c-arrows-right-left') ->requiresConfirmation() // ->label(__()) ->after(function ($record) { $newStatus = $record->status === 1 ? 0 : 1; $record->update(['status' => $newStatus]); }), ]) ->bulkActions([ // Tables\Actions\BulkActionGroup::make([ // Tables\Actions\DeleteBulkAction::make(), // ]), ]) ->query($query) ; } public static function getPages(): array { return [ 'index' => Pages\ManageProjects::route('/'), ]; } }