public function store(PropertyFormRequest $request) { $user = Auth::user(); $property = new Property(); $ownerEmail = $request->get('owner', $user->email); $owner = User::where('email', $ownerEmail)->firstOrFail(); $property->user()->associate($owner); if ($request->has('listing_referral')) { $listingReferral = User::where('email', $request->input('listing_referral'))->firstOrFail(); $property->referralList()->associate($listingReferral); } if ($request->has('selling_agent')) { $agentSelling = User::where('email', $request->input('selling_agent'))->firstOrFail(); $property->agentSell()->associate($agentSelling); } if ($request->has('selling_referral')) { $agentReferral = User::where('email', $request->input('selling_referral'))->firstOrFail(); $property->referralSell()->associate($agentReferral); } if ($user->is('agent')) { $property->agentList()->associate($owner); $property->status = Property::STATUS_INACTIVE; } $data = $request->all(); if ($request->input('point_map') != 1) { $data['latitude'] = NULL; $data['longitude'] = NULL; } $property->fill($data); $property->checkout_at = Carbon::now(); $property->generateListingCode(); $property->processViewingSchedule($request->all()); $property->save(); $checkedPortals = []; foreach ($request->input('property_portals', []) as $checkedPortal) { $checkedPortals[$checkedPortal] = ['user_id' => $user->id]; } $property->propertyPortals()->sync($checkedPortals); if ($request->has('sell_package')) { $property->packages()->attach([$request->input('sell_package') => ['addons' => implode('|', $request->input('features.sell', []))]]); } if ($request->has('rent_package')) { $property->packages()->attach([$request->input('rent_package') => ['addons' => implode('|', $request->input('features.rent', []))]]); } return redirect()->route('admin.property.index')->with('messages', ['Property is successfully created.']); }
public function postCreate(PropertyFormRequest $request) { $property = new Property($request->all()); $property->status = Property::STATUS_DRAFT; $property->user()->associate(Auth::user()); $property->processViewingSchedule($request->all()); $property->save(); if ($request->input('action') == 'save_information') { return redirect()->route('frontend.property.edit', ['id' => $property->id])->with('messages', [trans('property.messages.save_successful')]); } elseif ($request->input('action') == 'save_continue') { return redirect()->route('frontend.property.details', ['id' => $property->id]); } }