I have this if statement, if no $address information has been added to a user, then create, else go on.
public function getIndexEditClient(Request $request, $id) {
$regions = DB::table("regions")->pluck("name","id");
$address = Address::where('id', $request->address_id)->with('region')->first();
if(empty($address)){
$address = Address::create([
'street_name',
'house_number',
'postcode',
'city_id',
'country_id',
'region_id'
]);
// assiociate address with user
//then save it
}else{
$data = $this->data->getEditClient($id);
$admins = $this->data->getAdmin();
return view('client.edit', [
'client' => $data,
'admins' => $admins,
'regions' => $regions,
'address' => $address
]);
}
}
The only thing is, i have to associate the user(client) with the addres @ the commented lines. I don't get it to work.