api code global jain
This commit is contained in:
77
app/Http/Requests/Api/Vihar/DeleteViharRequest.php
Normal file
77
app/Http/Requests/Api/Vihar/DeleteViharRequest.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Api\Vihar;
|
||||
|
||||
use App\Rules\DeleteVihar;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class DeleteViharRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function authorize()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\Validation\Validator
|
||||
*/
|
||||
protected function getValidatorInstance()
|
||||
{
|
||||
$this->request->set('delete', 1);
|
||||
|
||||
return parent::getValidatorInstance();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
$array = [
|
||||
'delete' => 'sometimes',
|
||||
];
|
||||
|
||||
$startDate = Carbon::createFromFormat('Y-m-d H:i:s', $this->vihar->start_date .' '. '00:00:00');
|
||||
$todayDate = Carbon::createFromFormat('Y-m-d H:i:s', Carbon::now()->format('Y-m-d') .' '. '00:00:00');
|
||||
$result = $todayDate->eq($startDate);
|
||||
|
||||
if ($result) {
|
||||
$array['delete'] = [new DeleteVihar($this->vihar)];
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
if (Request::wantsJson()) {
|
||||
throw new HttpResponseException(response()->json(['message' => $validator->errors()->first(), 'error' => true, 'status' => 422], 422));
|
||||
} else {
|
||||
throw new ValidationException($validator);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'start_time.after' => 'Please enter a time after the current time.',
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user