Class App\Http\Controllers\PostController does not exist
If composer dumpautoload
is not helping then check if you have proper namespace
declaration in PostController.php
and double check for typos in class name/route declaration.
If this fails check composer.json
for autoload configuration, it should have something like this:
"autoload": {
"psr-4": {
"App\\": "app/"
}
},
As a side note you could use something like this:
Route::get('blog',PostController::class . '@index');
or
Route::get('blog',\App\Http\Controllers\PostController::class . '@index');
With this any decent IDE should give some kind of a warning if it can't find the file/there's a typo
Edit:
Your file should have a line like this
namespace App\Http\Controllers;
At the beggining of the file, right after <?php
or <?php declare(strict_types = 1);
if you're using php7 strict mode
Getting Class App\Http\Controllers\PostController does not exist error in Laravel project
You have an invisible character:
$post->tags()->sync($request->tags, false);<feff>
If your editor has a way to view non-printable characters, that might show characters like this.
ReflectionException in Route.php line 280. Class App\Http\Controllers\PostController does not exists
Running "composer dump-autoload -o" solved this issue.
Class 'App\Http\Controllers\App\Article' not found Laravel 5.6
To fix your issue, change:
<?php
namespace App;
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use app\Article;
In your controller to:
<?php
namespace App\Http\Controllers; // <- removing duplicate namespace
use Illuminate\Http\Request;
use App\Article; // <- Case sensitive, use App\, not app\
Other than that, I would really encourage you to read the documentation of Laravel, because this code is not really using Laravel.
You do not have to use session_start()
as in Laravel you have Session.
You do not have to work with superglobals as $_POST
, because you can use Laravel's Request objects.
You should not handle request data in your models, that's what your controller and/or services are for, this layer (request data) should not 'bleed' into your models like this.
You are using PDO statements, and totally bypass Laravel's Eloquent ORM.
I also see a lot of conditional requires, something that you should not do if you were using Laravel's service container.
With all of this, you are practically skipping every bit of functionality of Laravel and you are basically using the entire framework just for routing.
Class App/Http/Controllers/View Not Found error
The problem is not the actual view but the class View
. You see when you just reference a class like View::make('tickets.bus.index')
PHP searches for the class in your current namespace.
In this case that's App\Http\Controllers
. However the View
class obviously doesn't exists in your namespace for controllers but rather in the Laravel framework namespace. It has also an alias that's in the global namespace.
You can either reference the alias in the root namespace by prepending a backslash:
return \View::make('tickets.bus.index');
Or add an import statement at the top:
use View;
Related Topics
How to Get Next Id of Autogenerated Field in Laravel for Specific Table
How to Pass an Array Within a Query String
How to Get Part of Url Before Last Slash With PHP
Laravel: Pdoexception: Could Not Find Driver
Convert HTML Form Data into a Pdf File Using PHP
Fatal Error: Call to Undefined Function Sqlsrv_Connect()
How to Send an Email Using PHP
How to Create Cron Job Using PHP
How to Update Field to Add Value to Existing Value
How to Remove Query Part from $Request->All() in Laravel Framework
How to Capitalize First Letter in Laravel Blade
Session Destroy When One Browser Tab Gets Closed
Mysql Combine Two Columns into One in Query
Check If a Specific Value Exists At a Specific Key in Any Subarray of a Multidimensional Array