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