/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $http, Residence $residence) { // save newly created residence data $residence->nickname = $http->nickname; $residence->address1 = $http->address1; $residence->address2 = $http->address2; $residence->city = $http->city; $residence->state = $http->state; $residence->zipcode = $http->zipcode; $residence->num_residents = $http->num_residents; $residence->monthly_rent = $http->rent; // save new residence to the database $residence->save(); // insert relationship between authenticated user // and the newly created residence $residence->residents()->attach(Auth::user()->id); return redirect('residences'); }