66 lines
1.6 KiB
PHP
66 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Rules;
|
||
|
|
|
||
|
|
use Illuminate\Contracts\Validation\Rule;
|
||
|
|
use App\Models\Vihar;
|
||
|
|
use Carbon\Carbon;
|
||
|
|
use Illuminate\Support\Facades\Log;
|
||
|
|
|
||
|
|
class ViharStorePerDay implements Rule
|
||
|
|
{
|
||
|
|
|
||
|
|
public $sant_id;
|
||
|
|
public $vihar_id;
|
||
|
|
public $start_date;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Create a new rule instance.
|
||
|
|
*
|
||
|
|
* @return void
|
||
|
|
*/
|
||
|
|
public function __construct($data, $vihar_id = null)
|
||
|
|
{
|
||
|
|
$this->sant_id = $data['sant_id'];
|
||
|
|
$this->vihar_id = $vihar_id;
|
||
|
|
$this->start_date = $data['start_date'];
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Determine if the validation rule passes.
|
||
|
|
*
|
||
|
|
* @param string $attribute
|
||
|
|
* @param mixed $value
|
||
|
|
* @return bool
|
||
|
|
*/
|
||
|
|
public function passes($attribute, $value)
|
||
|
|
{
|
||
|
|
$santID = $this->sant_id;
|
||
|
|
$numberOfPosts = Vihar::where('sant_id', $this->sant_id)
|
||
|
|
// ->orWhere( function ($query) use ($santID) {
|
||
|
|
// return $query->whereHas('viharThana', function ($subQuery) use ($santID) {
|
||
|
|
// $subQuery->where('vihar_thanas.sant_id', $santID);
|
||
|
|
// })->orWhere('vihars.sant_id', $santID);
|
||
|
|
// })
|
||
|
|
->where('id', '<>', $this->vihar_id)
|
||
|
|
->whereDate('start_date', $this->start_date)
|
||
|
|
// ->whereDate('created_at', Carbon::today())
|
||
|
|
->count();
|
||
|
|
if ($numberOfPosts >= 2) {
|
||
|
|
return false;
|
||
|
|
} else {
|
||
|
|
return true;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the validation error message.
|
||
|
|
*
|
||
|
|
* @return string
|
||
|
|
*/
|
||
|
|
public function message()
|
||
|
|
{
|
||
|
|
return 'Only 2 Vihaar`s can be added for any sant in a day';
|
||
|
|
}
|
||
|
|
}
|