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