I have a project to check shipping rates using Laravel 11, I already have a table with prices that have been determined from origin to destination.
I use a search form with these 2 fields, but how can I swap the search, for example origin 1 to destination 2 or origin 1 to destination 2, and the results are still in the same column. And if the origin and destination are different then the results should not be displayed or will be null. For example, origin 3 to destination 2.
I use the get method but the search results do not match what is in the database table.
Why does a search with input that does not match the data table still appear with a different origin and destination? The result should be null because it is not in the column?
I have tried the following code but it doesn’t work as I expected. And This is some of the code I used
From Search
<form action="{{ url('rates') }}" method="GET">
@csrf
<div class="form-row align-items-center row">
<div class="col-md-5">
<label>Origin</label>
<select class="form-control single-select-field" name="origin">
<option selected>Origin...</option>
@foreach ($cities as $city)
<option value="{{ $city->id }}">{{ $city->id}}</option>
@endforeach
</select>
</div>
<div class="col-md-5">
<label>Destination</label>
<select class="form-control single-select-field" name="destination">
<option selected>Destination...</option>
@foreach ($cities as $city)
<option value="{{ $city->id }}">{{ $city->id }}</option>
@endforeach
</select>
</div>
<div class="col-md-6 my-3">
<button type="submit" class="btn btn-warning btn-block">Check Rates</button>
</div>
</div>
</form>
Rates Controller
$origin = $request['origin'];
$destination = $request['destination'];
$result = RouteModel::where(['origin' => $origin, 'destination' => $destination])->orWhere(['destination' => $origin, 'origin' => $destination])->first();
return $result;
Thank you for the help