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