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