This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

Wouter
Wouter

Hello,

I don't understand what I do wrong in my routes.php of my plugin file. I get a 404 error. I don't see anywhere a messages whats going wrong and I have no idea anymore where to search whats wrong. My route is:

Route::get('/test', [
    'as' => 'testroute',
    'uses' => 'name\pluginName\Classes\Custom@index'
]);

The I have in /plugins/name/plugin/Classes/costum.php

namespace name\PluginName\Classes;

use Cms\Classes\Controller;
class Custom extends Controller
{
    public function index()
    {
        dd('Working');
    }
}

What do I wrong, I don't get it.

Last updated

Daniel81
Daniel81

Not sure if it's just a typo, but your plugin class filename is costum.php and in that file the classname is Custom

alxy
alxy

routes.php is for frontend routes, whereas Cms\Classes\Controller is the base class for a backend controller. These two dont play nice together (or - in other words - not at all). You should use a regular laravel controller or any custom class, that in the end returns a Response.

An example for the usage of routes.php in a plugin you can find here: https://github.com/responsiv/pay-plugin/blob/master/routes.php

Wouter
Wouter

I understand what I did wrong. So I have created a laravel route.

Route::any('/tester', [Vendor\pluginname\testing\test', 'something']);

My file class file is now:

namespace Vendor\pluginname\testing;
class something extends test
{
function something()
    {
        //my code
    }
}

Now I get the follow error:

FatalErrorException in test.php line 10: Class 'Vendor\pluginname\testing\test' not found

I try to find the documentation how to create a class but I did not understand it right or do not have find the right documentation. Have someone who have a example for this ? I have study on the link Alxy give but I don't get I right till now....

alxy
alxy

This is basic PHP. You need to learn or understand the basics of php to write plugin for October ;) You can't simply use random names like test and expect these classes exist. They only exist, if you create them. Also, your routes.php contains syntax errors, which will result in a fatal/parse error as well.

Wouter
Wouter

I understood the error wrong. But I understand now how it works. (at least a little). I have used https://github.com/daftspunk/oc-laravelapi-plugin to see what I did wrong.

dshoreman
dshoreman

Namespaces don't include the Vendor folder. You'll find it useful to read up on namespacing, in particular PSR-0 and PSR-4 autoloading standards, as well as how Composer works.

andre_yang
andre_yang

If i May get you, you have a Controller named 'Custom' and you want to create a route to index().
---Try this code in your route
Route::any('test', 'name\PluginName\Classes\Custom@index')
or
Route::get('test', 'name\PluginName\Classes\Custom@index')

Last updated

andre_yang
andre_yang

doninyangm40018 said:

If i May get you, you have a Controller named 'Custom' and you want to create a route to index(). ---Try this code in your route Route::any('test', 'name\PluginName\Classes\Custom@index') or Route::get('test', 'name\PluginName\Classes\Custom@index')

1-9 of 9

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.