In one of the components of my plugin, I've got a function which reads user input (using Input::get()
), creates a Model
and saves it to the database. The data is submitted to this function via a html form. Now I want to allow users to add new data via Rest API
too. So I create a file called routes.php
in the root directory of my plugin and define a route for posting data. As it's logical to reuse the code that is already available in my plugins component, I tried to map the route to the already available component function:
Route::post('/items', 'Acme\Plugin\Components\ItemsList@addItem');
But this does not work and I get the following error:
The component Acme\\Plugin\\Components\\ItemsList does not contain a method getAfterFilters
Is this how the code should be reused in my Rest API? Why am I getting this error?
make a controller with no extend and use dependency injection for the component in the constructor
or
extend from
Illuminate\Routing\Controller
and dependecy injection
you can use the "Route::resource"
function
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.