i want to delete a row from stored session array. I could successfully delete it by sending the row number statically like in the code line below. But here i want to do it dynamically by passing the Array Row ID or line number. I want to replace the '0' with 'item_id' that is the array row number or id. How do i get that Id from array ?
$request->session()->pull('quoteSession.'.$id.'.vibrantScope.0');
This is my Array Console Log after deleting the first record using code above.
quoteSession:
125:
vibrantScope:
1: "Array line 2"
2: "Array line 3"
3: "Array line 4"
4: "Array line 5"
here is my Blade code
@foreach(Session::get('quoteSession.'.$lead->id.'.vibrantScope') as $item)
<tr>
<td scope="row">{{$loop->iteration}}</td>
<td class="p-1 min-w-100" width="">
{{$item}}
</td>
<td class="text-center">
<a href="javascript:void(0);" onclick="removeScopeSession('{{$lead->id}}', '{{$item_id}}')" id="removeScope" title="Remove Scope" class="text-danger h6"><span class="fa fa-minus-circle"></span></a>
</td>
</tr>
@endforeach
Here is my onClick Ajax call function to call delete controller
function removeScopeSession(lead_id, item_id){
$.ajax({
type: "post",
url:"/scope/ajaxRemoveVibrantScopeSession",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data:{
lead_id : lead_id,
item_id : item_id,
},
dataType: 'json',
success: function(response){
console.log(response);
$("#tblVibrantScope").load(" #tblVibrantScope > *");
toastr.success(' ', 'Scope Removed', {timeOut: 3000, positionClass: 'toast-bottom-right'});
},
error: function(error){
console.log(error);
toastr.error(' ', 'Scope not Removed', {timeOut: 3000, positionClass: 'toast-bottom-right'});
}
});
}
Here is my controller function. here i want to replace the '0' with 'item_id' that is the array row number or id.
public function ajaxRemoveVibrantScopeSession(Request $request)
{
$id = $request->lead_id;
$item_id = $request->item_id;
$delete_data = 'quoteSession.'.$id.'.vibrantScope.0';
$request->session()->forget($delete_data);
return $request->session()->all();
}