Controller exists but Lumen says it does not exist

Asked

Viewed 216 times

2

My routes are like this. http://localhost:8080/api/v1/Communities <- this is the url I’m requesting

$app->group(['prefix' => 'api/v1'], function($app) {

$app->get('/', 'CommunitiesController@index');

}

Essa é o print do controller em seu devido lugar.

My controller is like this

<?php

namespace App\Models\Controllers;

use App\Models\Communities;

class CommunitiesController
{
    public function index()
    {
        return "Cheguei no Controller";
    }
}

But the message I get in the request is that

Sorry, the page you are looking for could not be found.
(1/1) NotFoundHttpException

How To Solve?

  • You have accessed the URL api/v1/communities, but in the code defined only api/v1/. Is that right? It shouldn’t be get("/communities", ...)?

  • $app->get('Communities', 'Communitiescontroller@index')... :/

1 answer

1


In addition to the route observation which should be so:

$app->group(['prefix' => 'api/v1'], function($app) 
{
    $app->get('communities', 'CommunitiesController@index');
}

lack the inheritance of the class Controller for its code, the correction that’s the one:

<?php namespace App\Http\Controllers;

use App\Models\Communities;

class CommunitiesController extends Controller
{
    public function index()
    {
        return "Cheguei no Controller";
    }
}

that is, its ComunitiesController failed to inherit Controller.

References

  • 1

    Show man... Very good, helped me a lot, Thank you!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.