Skip to content

Commit

Permalink
feat(request): add auth request
Browse files Browse the repository at this point in the history
  • Loading branch information
tikrack committed Jan 18, 2025
1 parent b0914bb commit ee649af
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Http\Requests\Auth\AuthRequest;
use App\Http\Trait\ApiResponseTrait;
use Illuminate\Http\Request;

class AuthController extends Controller
{
public function auth()
{
use ApiResponseTrait;

}
public function auth(AuthRequest $request) {}
}
37 changes: 37 additions & 0 deletions app/Http/Requests/Auth/AuthRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace App\Http\Requests\Auth;

use App\Http\Trait\ApiResponseTrait;
use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;

class AuthRequest extends FormRequest
{
use ApiResponseTrait;

/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return ['mobile' => 'required|digits:11'];
}

public function failedValidation(Validator $validator)
{
throw new HttpResponseException($this->fail($validator->errors(), 'Validation error', 400));
}
}

0 comments on commit ee649af

Please sign in to comment.