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:Jump to solution
->actions([
Tables\Actions\EditAction::make()->mutateFormDataUsing(function (array $data): array {
$resource = $this->getResource();
$record = $resource->getCurrentRecord();
...
25 Replies
no i need the resorece man
You can create another resource and use the same model I guess
protected static ?string $model = YourModel::class;
As above 🙂 you could even extend the other model.
and use
modifyQueryUsing
to customize the query
https://filamentphp.com/docs/3.x/panels/resources/listing-records#customizing-the-table-eloquent-query@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
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
sir i want the database notfication
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
php artisan queue:work
?let me try this
Really Thank you sir working now
ONE MORE question but unless i didnt run this comand the notfication is not stored and also not coming in the pannel
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.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();
}
Use mutateFormDataUsing
Solution
->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();
}),
here is my code please refactor me i just want to crate the medical record when i crate the medical request
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?
insted treat works for me thanx for ur support
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?
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?
["AFB Stain:1", "Wet Smear:1", "Gram Stain:1"] how to edit this in filament