I have a form in which i input two fields Activity_datetime_from and Activity_datetime_to. the problem is that when i update the form if i update these two fields then update function is working fine but when i update other fields not these two than it update these two fields automatically to 0000-00-00 00:00:00 like that. Here is the code of my update function:
public function update(UpdateActivity $request, $id)
{
$activity = Activity::find($id);
if(!$activity) {
return response()->json(['message'=>'Data not found', 404]);
}
$activity->update($request->except(['activity_type', 'activity_picture']));
if($request->hasFile('activity_picture')) {
$activity_picture = $request->file('activity_picture');
$activity_picture_name = time().'.'.$activity_picture->getClientOriginalExtension();
$path = public_path('Storage/ActivityImages');
$activity_picture->move($path, $activity_picture_name);
$activity->activity_picture = 'Storage/ActivityImages/'.$activity_picture_name;
}
if ($request->has('activity_address')) {
$location = $request->input('activity_address');
$client = new \GuzzleHttp\Client();
$geocoder = new Geocoder($client);
$geocoder->setApiKey(config('geocoder.key'));
$address = $geocoder->getCoordinatesForAddress($location);
$latitude = $address['lat'];
$longitude = $address['lng'];
}
$activity->latitude = $latitude;
$activity->longitude = $longitude;
$activity->save();
return redirect()->route('activities.index')
->with('success','Activity updated successfully');
}
Here is my view edit.blade.php
<div class="form-group">
{!!Form::label('activity_datetime_from','Activity From*:',['class'=>'col-md-2'])!!}
<div class="col-md-10">
<p></p>
{!!Form::date('activity_datetime_from', null, ['class'=>'form-control','activity_datetime_from'])!!}
<!-- {!!Form::text('dateTime-local', null, ['class'=>'form-control',])!!} -->
</div>
</div>
<div class="form-group">
{!!Form::label('activity_datetime_to','Activity To*:',['class'=>'col-md-2'])!!}
<div class="col-md-10">
<p></p>
{!!Form::date('activity_datetime_to', null, ['class'=>'form-control','activity_datetime_to'])!!}
</div>
</div>
<div class="form-group">
{!!Form::label('activity_address','Address*:',['class'=>'col-md-2'])!!}
<div class="col-md-10">
{!!Form::text('activity_address', null, ['class'=>'form-control','required'])!!}
</div>
</div>
I want if i will update other fields than these two field will not change it contains the existing value. Please help Thanks in Advance.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire