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