0

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?

B Faley
  • 17,120
  • 43
  • 133
  • 223
  • Acme\Plugin\Components\ItemsList implements some interface, and you must have a method getAfterFilters in it. or do not implement from that interface. – Asheliahut Oct 19 '17 at 20:19
  • @Asheliahut It extends `ComponentBase`, as all components do in OctoberCMS. – B Faley Oct 19 '17 at 20:21

1 Answers1

2

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

Peter Haberkorn
  • 259
  • 1
  • 9