Search endpoint not present
I've created a model and controller (several of them, in fact), and most of it seems to be working fine.
However, when I try to use the search endpoint, I get an error:
The POST method is not supported for route api/transaction-rule/search. Supported methods: GET, HEAD, PUT, PATCH, DELETE.
The output from php artisan route:list looks like this (just showing entries for this model, but in fact it's the same for all models):
GET|HEAD api/transaction-rule ......................... transaction-rule.index › API\TransactionRuleController@index
POST api/transaction-rule ......................... transaction-rule.store › API\TransactionRuleController@store
GET|HEAD api/transaction-rule/create ................ transaction-rule.create › API\TransactionRuleController@create
GET|HEAD api/transaction-rule/{transaction_rule} ........ transaction-rule.show › API\TransactionRuleController@show
PUT|PATCH api/transaction-rule/{transaction_rule} .... transaction-rule.update › API\TransactionRuleController@update
DELETE api/transaction-rule/{transaction_rule} .. transaction-rule.destroy › API\TransactionRuleController@destroy
GET|HEAD api/transaction-rule/{transaction_rule}/edit ... transaction-rule.edit › API\TransactionRuleController@edit
Is there something I specifically need to do, to enable the search endpoint?
Thanks in advance for any help.
@PatFox can you include your route declaration from web.php or the place where you have routes declared for this model? I think you are missing more than the search endpoint.
Hi,
Thanks for the response.
Here's a simplified version -- there are other routes in the original file but here's what I have for the model mentioned in the original post:
use Illuminate\Support\Facades\Route;
use Orion\Facades\Orion;
use App\Http\Controllers\API\TransactionRuleController;
Route::group(
[
'middleware' =>
[
'auth:sanctum'
]
],
function () {
Orion::resource(
'/transaction-rule',
TransactionRuleController::class
);
}
);
@PatFox this looks good and the endpoint should be available. What version of Orion are you using?
If I run composer show, I get
tailflow/laravel-orion 2.22.1
...which I think is the latest?
Interestingly, if I add the route manually:
Route::post(
'/transaction-rule/search',
[
TransactionRuleController::class,
'search'
]
);
...it works fine. So it's just the routing part that's not working.
Anyway, if you (or anyone else!) has any other ideas, I'd love to hear them. In the meantime, I guess I can just use this manual approach for now.
Hi @PatFox,
Have you tried naming your Orion resource like transaction-rule (without the slash) or transaction_rule to see, if it makes any difference?
Hi @alexzarbn,
OK I removed the initial slash, so:
// Transaction rules
Orion::resource(
'transaction-rule',
TransactionRuleController::class
);
and this has solved the problem. Listing routes now shows:
GET|HEAD api/transaction-rule ................................................... transaction-rule.index › API\TransactionRuleController@index
POST api/transaction-rule ................................................... transaction-rule.store › API\TransactionRuleController@store
POST api/transaction-rule/batch ................................... transaction-rule.batchStore › API\TransactionRuleController@batchStore
PATCH api/transaction-rule/batch ................................. transaction-rule.batchUpdate › API\TransactionRuleController@batchUpdate
DELETE api/transaction-rule/batch ............................... transaction-rule.batchDestroy › API\TransactionRuleController@batchDestroy
POST api/transaction-rule/search .......................................... transaction-rule.search › API\TransactionRuleController@search
GET|HEAD api/transaction-rule/{transaction_rule} .................................. transaction-rule.show › API\TransactionRuleController@show
PUT|PATCH api/transaction-rule/{transaction_rule} .............................. transaction-rule.update › API\TransactionRuleController@update
DELETE api/transaction-rule/{transaction_rule} ............................ transaction-rule.destroy › API\TransactionRuleController@destroy
Seems odd that it works with the slash for some routes, but not others.
Anyway, thanks for your help!