/** * Update the business service types. * * @param Business $business * @param Request $request * * @return Response */ public function update(Business $business, Request $request) { logger()->info(__METHOD__); logger()->info(sprintf('businessId:%s', $business->id)); $this->authorize('manageServices', $business); // BEGIN $servicetypeSheet = $request->input('servicetypes'); $regex = '/(?P<name>[a-zA-Z\\d\\-\\ ]+)\\:(?P<description>[a-zA-Z\\d\\ ]+)/im'; preg_match_all($regex, $servicetypeSheet, $matches, PREG_SET_ORDER); $publishing = collect($matches)->map(function ($item) { $data = array_only($item, ['name', 'description']); $data['slug'] = str_slug($data['name']); return $data; }); foreach ($business->servicetypes as $servicetype) { if (!$this->isPublished($servicetype, $publishing)) { $servicetype->delete(); } } foreach ($publishing as $servicetypeData) { $servicetype = ServiceType::firstOrNew($servicetypeData); $business->servicetypes()->save($servicetype); } flash()->success(trans('servicetype.msg.update.success')); return redirect()->route('manager.business.service.index', [$business]); }
/** * @test */ public function it_belongs_to_businesses() { $serviceType = new ServiceType(); $this->assertInstanceOf(BelongsTo::class, $serviceType->business()); }