How to validate without request in Laravel
Should be. Because $request->all()
hold all input data as an array .
$input = [ 'title' => 'testTitle', 'body' => 'text'];$input is your customs array.$validator = Validator::make($input, [ 'title' => 'required|unique:posts|max:255', 'body' => 'required',]);
Validator::make expects array and not a request object.You can pass any array and implements the rules on it.
Validator::make(['name' => 'Tom'], ['name' => 'required', 'id' => 'required']);
And it will validate the array. So $request object is not necessary.
You can achieve this by create request object like so:
$request = new Request([ 'id' => 1, 'body' => 'text']);$this->validate($request, [ 'id' => 'required', 'body' => 'required']);
and thus you will get all the functionality of the Request class