I have a code that posts details from a form that looks like this. Field that contains Ampang, Kuala Lumpur = area_slug

This form then goes into a controller that as a post function to save the values in a table. Below is the code in the post function:
if ( $this->outlet->locations->count() ) {
foreach ( $this->outlet->locations as $index => $location ) {
$area = Level2::find( $locations[ $index ][ 'area_id' ] );
$area_slug = ( $area ? $area->slug : '' );
$shipping_fee_value = (float)$locations[ $index ][ 'shipping_fee_value' ];
// two type of conditional checks
// $shipping_fee_allow_negotiate = !empty( $location[ 'shipping_fee_allow_negotiate' ] );
if ( !empty( $locations[ $index ][ 'shipping_fee_allow_negotiate' ] ) ) {
$shipping_fee_allow_negotiate = 1;
} else {
$shipping_fee_allow_negotiate = 0;
}
/**
* Update each location belongs to Outlet
* Laravel Model Insert
* @see https://laravel.com/docs/8.x/eloquent#updates
*/
$location->area_slug = $area_slug;
$location->shipping_fee_value = $shipping_fee_value;
$location->shipping_fee_allow_negotiate = $shipping_fee_allow_negotiate;
$location->update();
}
} else {
foreach ( $locations as $location ) {
$area = Level2::find( $location[ 'area_id' ] );
$area_slug = ( $area ? $area->slug : '' );
$shipping_fee_value = (float)$location[ 'shipping_fee_value' ];
// two type of conditional checks
// $shipping_fee_allow_negotiate = !empty( $location[ 'shipping_fee_allow_negotiate' ] );
if ( !empty( $location[ 'shipping_fee_allow_negotiate' ] ) ) {
$shipping_fee_allow_negotiate = 1;
} else {
$shipping_fee_allow_negotiate = 0;
}
/**
* Create Location and related it to Outlet with `outlet_id`
* Laravel Model Insert
* @see https://laravel.com/docs/8.x/eloquent#inserts
*/
$location = new Location();
$location->outlet_id = $this->outlet->id;
$location->area_slug = $area_slug;
$location->shipping_fee_value = $shipping_fee_value;
$location->shipping_fee_allow_negotiate = $shipping_fee_allow_negotiate;
$location->save();
}
}
So what I'm trying to achieve is to prevent the same area_slug being posted eg. Ampang, Kuala Lumpur in both Location 1 and Location 2 respective fields. I have the idea of getting the previous area_slug but I'm not sure how to do so. If there are any unclear details do comment.