I am using laravel backpack and in my update function there is a form which could be edited using edit
button of laravel which calls the update function.
and in my form I have an expiry_date
and a month
field which helps my client to update the subscription of his user. All is working fine and here is the code of my update function:
public function update(UpdateRequest $request)
{
date_default_timezone_set('asia/calcutta');
$month = $request->month;
$expiry = new Carbon($request->expiry_date);
$expiry_date = $expiry->addMonths($month);
$request['expiry_date'] = $expiry_date;
// your additional operations before save here
$redirect_location = parent::updateCrud($request);
// your additional operations after save here
// use $this->data['entry'] or $this->crud->entry
return $redirect_location;
}
NOW THE PROBLEM IS:
- whenever my client clicks on edit button and edits the fields other than
month
and clicks on update, it calculates the expiry date again but my client clicked the button to update some other details of his user.
I want to ask if there is any method or something which could help me in finding that :
if the user has clicked on select of month
and has selected a option from the select then only execute the adding month to expiry_date code
and if not then only update the details of the user without affecting the original expiry_date.
If this is not the way please help me in finding the correct way.
Thanks and Regards
As no body is answering the question.
I solved it by:
1) Allowing null values in months field.
2) And Setting a default value of month field to '0'.
Like this:
3) and then in update function I called the last value of the month if it is '0':
And this solved the problem!! Thanks