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