hashim199
Select All option in relationship Select
@Leandro Ferreira
i have a bill table and a service table now the bill and services have a many to many relationship. On one bill one service can be taken multiple times like remove of tooth . but when i select one service from the list it disappears and i cant select it multiple times , so i want that i should be able to select one service multiple times
//service model public function bills() : BelongsToMany { return $this->belongsToMany(Bill::class, 'bill_service') ->withTimestamps(); } //Bill Model public function services() : BelongsToMany { return $this->belongsToMany(Service::class, 'bill_service') ->withTimestamps(); } //Bill Resource Forms\Components\Select::make('service_code') ->relationship('services','code') ->multiple() ->reactive() ->preload() ->live() ->required(),
//service model public function bills() : BelongsToMany { return $this->belongsToMany(Bill::class, 'bill_service') ->withTimestamps(); } //Bill Model public function services() : BelongsToMany { return $this->belongsToMany(Service::class, 'bill_service') ->withTimestamps(); } //Bill Resource Forms\Components\Select::make('service_code') ->relationship('services','code') ->multiple() ->reactive() ->preload() ->live() ->required(),
7 replies
How to calculate field value based on two other fields?
TextInput::make('total')
->placeholder(function (Get $get,Set $set) {
$ser = $get('service_code');
$panell = $get('Panel');
$codes = []; $allcharges = []; $sumcharges=[];
if ($ser !== null && $panell !== null) { $codes = Service::whereIn('id', $ser) ->pluck('code') ->toArray();
$charges = Service::where('panel_name', $panell) ->whereIn('code', $codes) ->pluck('charges') ->toArray(); $allcharges = array_merge($allcharges, $charges); $sumcharges=array_sum($allcharges);
} $set('total', $sumcharges); }) ->reactive() ->live(), it is not working on edit page it show empty field
$codes = []; $allcharges = []; $sumcharges=[];
if ($ser !== null && $panell !== null) { $codes = Service::whereIn('id', $ser) ->pluck('code') ->toArray();
$charges = Service::where('panel_name', $panell) ->whereIn('code', $codes) ->pluck('charges') ->toArray(); $allcharges = array_merge($allcharges, $charges); $sumcharges=array_sum($allcharges);
} $set('total', $sumcharges); }) ->reactive() ->live(), it is not working on edit page it show empty field
13 replies
Update field state every time other field updated without using $set()
TextInput::make('total')
->placeholder(function(Get $get){
$ser = $get('service_code');
$panell = $get('Panel');
// Initialize an array to store the codes $codes = []; $allcharges = []; $sumcharges=0;
// Check if both $ser and $panell are not null if ($ser !== null && $panell !== null) { // Retrieve codes from the database based on $ser $codes = Service::whereIn('id', $ser) ->pluck('code') ->toArray();
// Implement the query to fetch charges based on $panell // Assuming you have a table named "charges" with columns "panel_name" and "charge" $charges = Service::where('panel_name', $panell) ->whereIn('code', $codes) ->pluck('charges') ->toArray();
// Insert charges into $allcharges array $allcharges = array_merge($allcharges, $charges); $sumcharges=array_sum($allcharges); }
// Print the extracted codes and charges using var_dump // var_dump($sumcharges);
return $sumcharges; }) ->live(), it is not saving the data in the database
// Initialize an array to store the codes $codes = []; $allcharges = []; $sumcharges=0;
// Check if both $ser and $panell are not null if ($ser !== null && $panell !== null) { // Retrieve codes from the database based on $ser $codes = Service::whereIn('id', $ser) ->pluck('code') ->toArray();
// Implement the query to fetch charges based on $panell // Assuming you have a table named "charges" with columns "panel_name" and "charge" $charges = Service::where('panel_name', $panell) ->whereIn('code', $codes) ->pluck('charges') ->toArray();
// Insert charges into $allcharges array $allcharges = array_merge($allcharges, $charges); $sumcharges=array_sum($allcharges); }
// Print the extracted codes and charges using var_dump // var_dump($sumcharges);
return $sumcharges; }) ->live(), it is not saving the data in the database
14 replies
Custom form action help
@Leandro Ferreira solved now how can i open the action in new window, shouldOpenInNewTab will not work here any suggestions
->action(
function ($data)
{
$companyName=$data['companyname'];
$fromDate=$data['from'];
$toDate=$data['to'];
return redirect()->route('invoice-genrate',[$companyName,$fromDate,$toDate]);
}
),
10 replies
Custom form action help
@Leandro Ferreira now its is not going inside function and there is no error 😦
Actions\Action::make('PanelInvoice')->form([
TextInput::make('companyname')
->label('Company Name'),
DatePicker::make('from')->default(null),
DatePicker::make('to')->default(null),
])
->action(
function (array $data)
{
$companyName=$data['companyname']; $fromDate=$data['from']; $toDate=$data['to']; return route('invoice-genrate',[$companyName,$fromDate,$toDate]);
} ) Route::get('/invoice-genrate/{companyName}/{fromDate}/{toDate}', [BillPanelReports::class, 'createInvoice'])->name('invoice-genrate'); public function createInvoice(Request $request) { $companyName = $request->input('companyname'); $fromDate = $request->input('from'); $toDate = $request->input('to'); dd($companyName,$fromDate,$toDate); }
$companyName=$data['companyname']; $fromDate=$data['from']; $toDate=$data['to']; return route('invoice-genrate',[$companyName,$fromDate,$toDate]);
} ) Route::get('/invoice-genrate/{companyName}/{fromDate}/{toDate}', [BillPanelReports::class, 'createInvoice'])->name('invoice-genrate'); public function createInvoice(Request $request) { $companyName = $request->input('companyname'); $fromDate = $request->input('from'); $toDate = $request->input('to'); dd($companyName,$fromDate,$toDate); }
10 replies
Custom form action help
@Leandro Ferreira
Send the data of form to controller function from a custom action, i will be thankful to you for the help
Actions\Action::make('PanelInvoice')->form([
TextInput::make('companyname')
->label('Company Name'),
DatePicker::make('from')->default(null),
DatePicker::make('to')->default(null),
])
->action(function (array $data)
{
return route('invoice.create',$data); }) Routes: I have tried both i doest not Route::get('/invoice-genrate/{data}', [BillPanelReports::class, 'createInvoice'])->name('invoice-genrate'); Route::post('/invoice-cerate', [BillPanelReports::class, 'createInvoice'])->name('invoice.create'); controller function public function createInvoice(Request $request) { dd('hello'); $companyName = $request->input('companyname'); $fromDate = $request->input('from'); $toDate = $request->input('to');
}
return route('invoice.create',$data); }) Routes: I have tried both i doest not Route::get('/invoice-genrate/{data}', [BillPanelReports::class, 'createInvoice'])->name('invoice-genrate'); Route::post('/invoice-cerate', [BillPanelReports::class, 'createInvoice'])->name('invoice.create'); controller function public function createInvoice(Request $request) { dd('hello'); $companyName = $request->input('companyname'); $fromDate = $request->input('from'); $toDate = $request->input('to');
}
10 replies
get a field value in an action
@Dennis Koch sorry to bother you but i am stuck
if i eturn route('panel-invoice', $parameters['companyname']); it shows no error just reload
now if i return return route('panel-invoice', $parameters); error Missing required parameter for [Route: panel-invoice] [URI: panel-invoice/{data}] [Missing parameter: data].
Route::get('/panel-invoice/{data}', [BillPanelReports::class, 'createInvoice'])->name('panel-invoice');
public function createInvoice( $data)
{
dd($data);
} Actions\Action::make('PanelInvoice')->form([ TextInput::make('companyname') ->label('Company Name'), DatePicker::make('from')->default(null), DatePicker::make('to')->default(null), ])->action(function (array $data) { $parameters = [ 'companyname' => $data['companyname'], 'from'=>$data['from'], 'to'=>$data['to'], // other parameters if needed ]; return route('panel-invoice', $parameters);}) ,
} Actions\Action::make('PanelInvoice')->form([ TextInput::make('companyname') ->label('Company Name'), DatePicker::make('from')->default(null), DatePicker::make('to')->default(null), ])->action(function (array $data) { $parameters = [ 'companyname' => $data['companyname'], 'from'=>$data['from'], 'to'=>$data['to'], // other parameters if needed ]; return route('panel-invoice', $parameters);}) ,
13 replies
get a field value in an action
Error: Array callback must have exactly two elements
Actions\Action::make('PanelInvoice')->form([
TextInput::make('companyname')
->label('Company Name'),
DatePicker::make('from')->default(null),
DatePicker::make('to')->default(null),
])->action(function (array $data)
{
$company=$data('companyname'); return route('panel-bill',$company); }) ,
$company=$data('companyname'); return route('panel-bill',$company); }) ,
13 replies