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