api code global jain
This commit is contained in:
56
app/Rules/DeleteVihar.php
Normal file
56
app/Rules/DeleteVihar.php
Normal file
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Rules;
|
||||
|
||||
use App\Models\Vihar;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Contracts\Validation\Rule;
|
||||
|
||||
class DeleteVihar implements Rule
|
||||
{
|
||||
|
||||
public $sant_id;
|
||||
public $start_date;
|
||||
public $start_time;
|
||||
public $vihar_id;
|
||||
|
||||
/**
|
||||
* Create a new rule instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($vihar = null)
|
||||
{
|
||||
$this->sant_id = $vihar['sant_id'];
|
||||
$this->start_date = $vihar['start_date'];
|
||||
$this->start_time = $vihar['start_time'];
|
||||
$this->vihar_id = $vihar['id'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the validation rule passes.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function passes($attribute, $value)
|
||||
{
|
||||
$numberOfVihar = Vihar::where('id', $this->vihar_id)->where('start_time', '<=', Carbon::now()->format('H:i'))->count();
|
||||
if ($numberOfVihar > 0) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation error message.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function message()
|
||||
{
|
||||
return 'Vihar is already started so you can`t delete it.';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user