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