action = $action; $this->request = $request; $this->model = $floorplan; $this->function = Str::camel($action); $this->executeAction(); return $this->model; } public function store(Floorplan $floorplan, array $request) { $attributes = $request; $attributes['user_id'] = user_id(); $attributes['user_type'] = user_type(); $floorplan = $floorplan->create($attributes); return $floorplan; } public function update(Floorplan $floorplan, array $request) { $attributes = $request; $floorplan->update($attributes); return $floorplan; } public function destroy(Floorplan $floorplan, array $request) { $floorplan->delete(); return $floorplan; } public function copy(Floorplan $floorplan, array $request) { $count = $request['count'] ?: 1; if ($count == 1) { $floorplan = $floorplan->replicate(); $floorplan->created_at = Carbon::now(); $floorplan->save(); return $floorplan; } for ($i = 1; $i <= $count; $i++) { $new = $floorplan->replicate(); $new->created_at = Carbon::now(); $new->save(); } return $floorplan; } }