Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 214 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controller Class Not Found - Lumen

#1
My Controller for my class 'Article' cannot be found.


I am needing to fetch all entries from the article table.

I am able to use the DB:: facade to pull what's in the DB, but when I try using Article::all() I get:

Class 'App\Http\Controllers\Article' not found

in ArticleController.php line 15
at Application->Laravel\Lumen\{closure}()

Line 15 looks like:

$article = Article::all();

This is what I've tried so far, but with no success:

- updated .env.example to .env and set up my DB credentials.

- in bootstrap/app.php I've uncommented `Dotenv::load(__DIR__.'/../');`

- In bootstrap/app.php I've uncommented `$app->withFacades(); $app->withEloquent();`

- I've tried to use the full route of the controller in routes.php: `$app->get('article', 'App\Http\Controllers\ArticleController@index');`

My model directory is located under app->Models and has my Article.php model:

<?php

# app/Models/Article.php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Article extends Model
{
protected $table = 'articles';
protected $fillable = ['title', 'content'];
}

My Controller is ArticleController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class ArticleController extends Controller{

public function index(){

$article = Article::all();

return response()->json($article);
}
}

And my routes.php

<?php

$app->get('article', 'ArticleController@index');

I really appreciate any help on this error. I've unfortunately spent the better part of 2 days on this.

Thanks.
Reply

#2
Just run `composer update`. a new autoload classmap will be generated and all your new composer will be ready to autoload after successful update.
Reply

#3
You need to have the proper namespace. Your `Article` model is in the `App\Models` namespace so you need to add this to the top of your controller:

use App\Models\Article;
Reply

#4
Thanks for your responses and for your answer @Thomas. I followed your response and was able to add the correct namespace in my controller.
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through