Resource page that can share the same Model

Hello how i Can create Resource page that can share the same Model , I want one resource for approval
Solution:
->actions([ Tables\Actions\EditAction::make()->mutateFormDataUsing(function (array $data): array { $resource = $this->getResource(); $record = $resource->getCurrentRecord(); ...
Jump to solution
25 Replies
alonemz
alonemzOP7mo ago
no i need the resorece man
LeandroFerreira
LeandroFerreira7mo ago
You can create another resource and use the same model I guess protected static ?string $model = YourModel::class;
toeknee
toeknee7mo ago
As above 🙂 you could even extend the other model.
Povilas K
Povilas K7mo ago
@alonemz if your case is just showing different records approved or not approved for different roles, for example, you may want to avoid two different resources and maybe just use modifyQueryUsing with a condition? https://laraveldaily.com/post/filament-table-modify-base-query-by-user-role-condition
alonemz
alonemzOP7mo ago
filament form request how to get can i use like this public function form(Form $form, Request $request): Form public static function form(Form $form): Form { return $form ->schema([ TextInput::make('name')->label('Name')->required(), TextInput::make('email')->label('Email')->required(), TextInput::make('phone')->label('Phone')->required(), TextInput::make('password')->label('password')->required(), TextInput::make('job_role')->label('Job Role')->required(), TextInput::make('type')->label('User Type')->required(), Notification::make() ->success() ->title('User Created , You Need focus ') ->sendToDatabase(auth()->user()), ]); } hello how can i stor to the db the notificaation
alonemz
alonemzOP7mo ago
sir i want the database notfication
alonemz
alonemzOP7mo ago
yes i have set this ->databaseNotifications(); to the panel and also i have done the migration but in resorec i set befor save protected function beforeCreate(): void { Notification::make() ->success() ->title('User Created , You Need focus ') ->sendToDatabase(auth()->user()); } like this but cant store
LeandroFerreira
LeandroFerreira7mo ago
php artisan queue:work ?
alonemz
alonemzOP7mo ago
let me try this
alonemz
alonemzOP7mo ago
Really Thank you sir working now
No description
alonemz
alonemzOP7mo ago
ONE MORE question but unless i didnt run this comand the notfication is not stored and also not coming in the pannel
LeandroFerreira
LeandroFerreira7mo ago
Confirming, are you utilizing a database driver in the queue connection? If you prefer not to use queues, set QUEUE_CONNECTION=sync in the .env file.
alonemz
alonemzOP7mo ago
hello public static function form(Form $form): Form { $user = auth()->user(); return $form->schema([ Textarea::make('description')->nullable(), Hidden::make('status')->default('open'), Hidden::make('user_id')->default($user->id), Hidden::make('approver_id')->default($user->manager_id), FileUpload::make('attachment') // Define file validation rules ]); } i have this form and i want to stor also this to othere db the medical_request_id and also the user_id the requester to medical_record table so i used like this but not working protected function beforeSave(): void { $resource = $this->getResource(); $record = $resource->getCurrentRecord(); // Create a new MedicalRecord instance $medicalRecord = new MedicalRecord(); // Set the user_id and medical_request_id for the MedicalRecord $medicalRecord->user_id = $record->user_id; $medicalRecord->medical_request_id = $record->id; // Save the MedicalRecord instance $medicalRecord->save(); }
HeyWeb
HeyWeb7mo ago
Use mutateFormDataUsing
Solution
HeyWeb
HeyWeb7mo ago
->actions([ Tables\Actions\EditAction::make()->mutateFormDataUsing(function (array $data): array { $resource = $this->getResource(); $record = $resource->getCurrentRecord(); // Create a new MedicalRecord instance $medicalRecord = new MedicalRecord(); // Set the user_id and medical_request_id for the MedicalRecord $medicalRecord->user_id = $record->user_id; $medicalRecord->medical_request_id = $record->id; // Save the MedicalRecord instance $medicalRecord->save(); }),
alonemz
alonemzOP7mo ago
here is my code please refactor me i just want to crate the medical record when i crate the medical request
alonemz
alonemzOP7mo ago
Hello Leandro here when i create the medical request i want also crate record to medical record table the requester id and the medical_request_id can you help me with this if you can?
alonemz
alonemzOP7mo ago
insted treat works for me thanx for ur support
alonemz
alonemzOP7mo ago
public function table(Table $table): Table { // Get the user ID $userId = $this->getOwnerRecord()->user_id; // Retrieve medical records for the user $medicalRecords = MedicalRecord::where('user_id', $userId)->get(); // Get the medical record IDs $medicalRecordIds = $medicalRecords->pluck('id'); // Retrieve vital signs for the medical records $vitalSigns = VitalSign::whereIn('medical_record_id', $medicalRecordIds)->get(); // Map the vital signs data $data = $vitalSigns->map(function ($vitalSign) { return [ 'user_id' => $vitalSign->user_id, 'temperature' => $vitalSign->temperature, 'blood_pressure' => $vitalSign->blood_pressure, 'heart_rate' => $vitalSign->heart_rate, 'respiratory_rate' => $vitalSign->respiratory_rate, 'oxygen_saturation' => $vitalSign->oxygen_saturation, ]; }); return $table ->viewData(['data' => $data]) ->columns([ TextColumn::make('user_id')->label('Patient ID'), TextColumn::make('temperature')->sortable()->searchable(), TextColumn::make('blood_pressure')->sortable()->searchable(), TextColumn::make('heart_rate')->sortable()->searchable(), TextColumn::make('respiratory_rate')->sortable()->searchable(), TextColumn::make('oxygen_saturation')->sortable()->searchable(), ]); how can i pass?
Sjoerd24
Sjoerd247mo ago
Will be mixed feelings for me if i ever get seriously sick and i see that this saves my vital information. Although working in health care for 12 years, probably most software i don’t want to see the inner workings of. I dont understand your question, could you reformulate?
alonemz
alonemzOP6mo ago
["AFB Stain:1", "Wet Smear:1", "Gram Stain:1"] how to edit this in filament
Want results from more Discord servers?
Add your server