Level 16
i believe you should create a Respository instead of a new class. It minimizes your efforts.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi,
I have a controller with two function that I need to call upload function from add function while upload function has the UploadRequest class as input.
How can I make an instance of UploadRequest class, and call upload function?!
Controller class:
class ImageController extends Controller
{
public function add(Request $request)
{
// code
// call $this->upload()
}
public function upload(UploadRequest $request)
{
// validate
$request = $request->validated();
// code
}
}
UploadRequest class:
class UploadRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'type' => 'required|string|in:avatar,place,review,meta',
'id' => 'required|numeric|integer|regex:/^[0-9]+$/'
];
}
}
Please or to participate in this conversation.