Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defining routes to a controller, Reflection errors #884

Open
DaWolfey opened this issue Dec 27, 2022 · 3 comments
Open

Defining routes to a controller, Reflection errors #884

DaWolfey opened this issue Dec 27, 2022 · 3 comments

Comments

@DaWolfey
Copy link

  • Themosis Version: 3.0.0
  • WordPress Version: 6.1.1
  • PHP Version: 8.1

Description

I must be doing something wrong here, my Laravel experience is not all that high so I am perfectly willing to accept user error, especially for such a rudimentary task.
I am getting errors when I try to define a route to a controller, either using the [Pagecontroller::class,'page'] methor, or the 'PageController@page' method.

Steps to reproduce

Fresh installation of Themosis with Wordpress, set app_debug to true in .env
Create a page in Wordpress named Test
Create a new controller with Artisan named PageController
In that controller add:

    public function Test() {
        return view('welcome');
    }

In routes/web.php add a route:
Route::any('page', ['test', 'uses' => [PageController::class,'Test']]);

Accessing the page via site.com/test gives:
ReflectionFunction::__construct(): Argument #1 ($function) must be of type Closure|string, array given

If the route is changed the other method as given in the docs:
Route::any('page', ['test', 'uses' => 'PageController@Test']);

We now get a new error:
Target class [PageController] does not exist.

Note that if the route is:
Route::any('page', ['test', 'uses' => 'App\Http\Controllers\PageController@Test']);

It does work as expected, but the documentation explicitly says that it shouldn't be necessary.

@DaWolfey
Copy link
Author

I should add that in Themosis 2.1, using the following did work as expected:
Route::any('page', ['test', 'uses' => 'PageController@Test']);

@danieldunderfelt
Copy link

Running into this too now that I upgraded to 3.1. Can it be fixed @jlambe?

@jlambe
Copy link
Contributor

jlambe commented Oct 1, 2023

Default controller namespace has been removed for routes in version 3.0. You can uncomment the default namespace located in the RouteServiceProvider file: https://github.com/themosis/themosis/blob/6d956e07fdd4c058b675e3837063213cfab4fa7e/app/Providers/RouteServiceProvider.php#L27

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants