/** * Handle domain check from homepage * * @param DomainCreateRequest $request * @return Response */ public function postCheckDomain(DomainCreateRequest $request) { $zone = $this->zoneRepository->findOneByEnabled($request->zone_id, ['id', 'name']); if (!$zone) { abort(404); } try { Domain::checkDomainAvailability($request->name, $zone); if (Auth::guest()) { return back()->withInput($request->only('name', 'zone_id'))->with('domain_status', trans('front.domain.domain_available_guest', ['domain' => $zone->getDomainName($request->name), 'sign_up_route' => route('user.register')])); } else { return back()->withInput($request->only('name', 'zone_id'))->with('domain_status', trans('front.domain.domain_available', ['domain' => $zone->getDomainName($request->name), 'register_domain' => route('user.domain.create', ['domain' => $request->name, 'zone' => $request->zone_id])])); } } catch (DomainNotAvailableException $e) { return back()->withInput($request->only('zone_id'))->with('domain_status', trans('front.domain.domain_not_available', ['domain' => $zone->getDomainName($request->name)])); } }
/** * Store a newly created User Domain in storage. * * @param DomainCreateRequest $request * @return Response */ public function postCreate(DomainCreateRequest $request) { try { $zone = $this->zoneRepository->findOneByEnabled($request->zone_id, ['id']); Domain::checkDomainAvailability($request->name, $zone); } catch (DomainNotAvailableException $e) { return back()->withInput($request->only('name', 'zone_id'))->withErrors(['name' => $e->getMessage()]); } // just save to database $userDomain = $request->only('name', 'zone_id'); $userDomain['user_id'] = Auth::user()->id; $expired = sprintf("P%dY", (int) Setting::get('domain_registration_year')); $userDomain['expired_at'] = (new \DateTime())->add(new \DateInterval($expired)); $newDomain = $this->domainRepository->create($userDomain); // add user domains_total $datas = ['domains_total' => Auth::user()->domains_total + 1]; $this->userRepository->update($datas, Auth::user()->id); return redirect()->route('user.domain.list')->with('success', trans('front.domain.success_register', ['domain_name' => $newDomain->complete_domain_name])); }