Remove them from that array again. The error before was the correct one
Next make sure the filename of the class matches the class name exactly
I'm new in laravel. I appreciate your help guys. trying to build a json API for backend of a newsdashboard with laravel. made migrations. I created the routes. made models. made the controller. Now I'm getting this error whenever I want to serve:
Method App\Http\Controllers\NewsController::isDeferred does not exist.
Here is my code guys:
Here are my routes:
use Illuminate\Support\Facades\Route;
use App\NewsItem;
use App\Http\Controllers\NewsController;
Route::get('/', function () {
return view('welcome');
});
Route::get('/news', 'App\Http\Controllers\NewsController@index')->name('news.index');
Route::get('/news/{newsItem}', 'App\Http\Controllers\NewsController@show')->name('news.show');
Route::post('/news', 'App\Http\Controllers\NewsController@store')->name('news.store');
Route::patch('/news/{newsItem}', 'App\Http\Controllers\NewsController@update')->name('news.update');
Route::delete('/news/{newsItem}', 'App\Http\Controllers\NewsController@destroy')->name('news.destroy');
Route::get('/news/create', 'App\Http\Controllers\NewsController@create')->name('news.create');
Route::get('/news/{newsItem}/edit', 'App\Http\Controllers\NewsController@edit')->name('news.edit');
Here is the controller that was mentioned in the routes:
<?php
namespace App\Http\Controllers;
use App\Category;
use App\NewsItem;
use App\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class NewsController extends Controller
{
/**
* Display a listing of the news items.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$newsItems = NewsItem::with('category', 'tags')->get();
return response()->json($newsItems);
}
// and the rest of the code which are rest of the CRUD functions... and some validations
}
Here is NewsItem mode:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class NewsItem extends Model
{
// Specify the table name for the model
protected $table = 'news_items';
// Specify the fillable fields for the model
protected $fillable = [
'title',
'body',
'category_id',
'url',
];
// Define the relationships for the model
public function category()
{
return $this->belongsTo(Category::class);
}
public function tags()
{
return $this->belongsToMany(Tag::class);
}
}
And made two other similar models for Tag and Category too.
Before getting this error I got another error :
Class "App\NewsItem" not found
and then I added my controller and model classes to the $providers array in the config/app.php file and now I'm getting this error in the title.
I tried: composer dump-autoload
and I'm getting :
Class App\Category located in D:/news-dashboard/app\Models\Category.php does not comply with psr-4 autoloading standard. Skipping.
Class App\NewsItem located in D:/news-dashboard/app\Models\NewsItem.php does not comply with psr-4 autoloading standard. Skipping.
Class App\Tag located in D:/news-dashboard/app\Models\Tag.php does not comply with psr-4 autoloading standard. Skipping.
> Illuminate\Foundation\ComposerScripts::postAutoloadDump
> @php artisan package:discover --ansi
In Controller.php line 68:
Method App\Http\Controllers\NewsController::isDeferred does not exist.
Script @php artisan package:discover --ansi handling the post-autoload-dump event returned with error code 1
@m11ad the namespace is wrong then
Fix the model
namespace App\Models;
And the import in the controller
use App\Models\NewsItem;
Please or to participate in this conversation.