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