08-06-2023, 04:22 PM
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.
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.