NigelRel3 Posted April 20, 2017 Share Posted April 20, 2017 I've managed to sort of a simple REST test, which uses a standard model with a single field for the key. I've also managed to get Eloquent to deal with composite key models. Now I want to see how I can put them both together - in the simplest way possible! So i would like it to fit into the standard Route::resource('/Bin', 'RestBinController'); This only seems to expect a single parameter and so if I try /api/Bin/1/2 it doesn't recognise the path. I could split it out into the get/post... methods (and it may come down to this) but I wanted to check if I was missing something before I did this. Quote Link to comment https://forums.phpfreaks.com/topic/303754-laravel-54-rest-controller-with-composite-key-table/ Share on other sites More sharing options...
dkub Posted April 20, 2017 Share Posted April 20, 2017 Looks like using dot notation will get you part of the way there. Route::resource('bin/foo.bar', 'RestBinController'); ❯ ./artisan route:list +--------+-----------+------------------------------+-----------------+------------------------------------------------+--------------+ | Domain | Method | URI | Name | Action | Middleware | +--------+-----------+------------------------------+-----------------+------------------------------------------------+--------------+ | | GET|HEAD | / | | Closure | web | | | GET|HEAD | api/user | | Closure | api,auth:api | | | GET|HEAD | bin/foo/{foo}/bar | foo.bar.index | App\Http\Controllers\RestBinController@index | web | | | POST | bin/foo/{foo}/bar | foo.bar.store | App\Http\Controllers\RestBinController@store | web | | | GET|HEAD | bin/foo/{foo}/bar/create | foo.bar.create | App\Http\Controllers\RestBinController@create | web | | | GET|HEAD | bin/foo/{foo}/bar/{bar} | foo.bar.show | App\Http\Controllers\RestBinController@show | web | | | PUT|PATCH | bin/foo/{foo}/bar/{bar} | foo.bar.update | App\Http\Controllers\RestBinController@update | web | | | DELETE | bin/foo/{foo}/bar/{bar} | foo.bar.destroy | App\Http\Controllers\RestBinController@destroy | web | | | GET|HEAD | bin/foo/{foo}/bar/{bar}/edit | foo.bar.edit | App\Http\Controllers\RestBinController@edit | web | +--------+-----------+------------------------------+-----------------+------------------------------------------------+--------------+ Not exactly the /api/bin/1/2 you were describing but close, and perhaps a little more descriptive. Quote Link to comment https://forums.phpfreaks.com/topic/303754-laravel-54-rest-controller-with-composite-key-table/#findComment-1545659 Share on other sites More sharing options...
dkub Posted April 20, 2017 Share Posted April 20, 2017 Oh wait. Composite keys. /api/bin/1/2 points to a single object. Disregard my earlier suggestion, then. I suspect resourceful controllers will fall short and you will need to be more declarative in your routing. Quote Link to comment https://forums.phpfreaks.com/topic/303754-laravel-54-rest-controller-with-composite-key-table/#findComment-1545661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.