I’m encountering a strange issue in my CrudController
when applying a base clause with a dynamic route parameter. I have a custom route like this:
Route::crud('box/{receive_order_id}/list', 'BoxCrudController');
The idea is to capture the receive_order_id
parameter from the URL and apply a base clause on the query. However, while the URL parameter is being passed correctly and can be logged, it doesn’t work when applied to the query. Hardcoding the value works fine.
Here’s the code with some inline comments for context:
protected function setupListOperation()
{
// Get the receive_order_id from the route
$receiveOrderId = request('receive_order_id');
// Debugging shows the value is passed correctly
// dd($receiveOrderId); // outputs "24"
// dd(gettype($receiveOrderId), $receiveOrderId === "24"); // Outputs: string, true
// Hardcoded value works perfectly
// $this->crud->addBaseClause('where', 'receive_order_id', "24" ); // works fine
// Checking the SQL generated by the query
// dd($this->crud->query->toSql()); // Outputs: "select * from `boxes` where `receive_order_id` = ?"
// dd($this->crud->query->getBindings()); // Outputs: [0 => "24"]
// Applying the URL parameter dynamically doesn't work (no results returned)
$this->crud->addBaseClause('where', 'receive_order_id', $receiveOrderId ); // no results
}
The Issue:
When I pass the receive_order_id
dynamically through the URL, it doesn’t return any results, even though the value and query appear to be correct.
Any ideas on what could be causing this issue?
What I’ve Tried:
- Logging the value:
request('receive_order_id')
outputs the correct value"24"
and the type isstring
. - Hardcoded base clause: Works fine with the hardcoded
"24"
. - Inspecting SQL and bindings: The query generated looks fine, with
receive_order_id = ?
and the correct binding of"24"
.
3