6 months ago

laravel 5.8 - cutom rule validation with array with values as paramter and query database

Posted 6 months ago by doproj123

I need to create a method that will retrieve several data from the form and substitute for querying to database. This is simple reservation. Before entering the database I need to know if the given date and car are aviable. Is it possible? Or maybe there are better solutions?


 <form method="POST" action="{{ route('/new/store') }}">
 <table style="width:100%">
    <th>Date 1</th>
    <th>Date 2</th>
    <td><input type="text" name="date1"></td>
    <td><input type="text" name="date2"></td>
    <td><input type="text" name="car"></td>
<button type="submit" class="btn btn-primary">{{ __('Add') }}</button>


 public function store(Request $request)
        'date1' => ['required', 'date', 'date_format:Y-m-d'],
        'date2' => ['required', 'date', 'date_format:Y-m-d'],
        'car' => ['required'],

ValidateDate.php // class which implements Rule

public function passes($attribute, $value) <------ $value can be array ?
    //if $value can be array can i do something like this

    $results = DB::select('select * from reseravation where (date_from <= '$value['date1']' and date_to >= '$value['date2']') and car = '$value['car']' ');

        return true;
        return false;

Please sign in or create an account to participate in this conversation.