Files
Global-Jain/app/Rules/DeleteVihar.php

57 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2025-11-05 10:37:10 +05:30
<?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.';
}
}