Hello I'm new to Laravel I store family member details inside the session by using the below method and i want to delete family member by using the index of the session please someone help me.
session()->push('families',$request);
Hello I'm new to Laravel I store family member details inside the session by using the below method and i want to delete family member by using the index of the session please someone help me.
session()->push('families',$request);
This is to do it using PHP array_search
function:
$families = session()->pull('families', []);
if(($key = array_search($deleteID, $families)) !== false) {
unset($families[$key]);
}
session()->put('families', $families);
// PS: specify index you want to remove on $deleteID variable
or more simple way:
$index = 0; // let's say it's index 0
$families = Session::get('families'); // save the array
unset($families[$index]); // remove value from array based on index
Session::put('families', $families); // set the array again
// PS: specify index you want to remove on $index variable