ReflectionException Class App\Http\Controllers\PostsController does not exist Lumen 5.5 - php

I am new to Lumen, and I got error when using Postman: ReflectionException Class App\Http\Controllers\PostsController does not exist
Here is my PostsController.php
namespace App\Http\Controller;
use App\Post;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class PostsController extends Controller{
/*content*/
}
I already checked location of my controller. I also read the same problem and tried the solutions, but it was not work for me. Can anyone tell me how to fix this? Thanks before

Controller's namespace is wrong, Check the namespace. Good luck
namespace App\Http\Controllers;

You have wrong namespace in your controller file.
You need to change it to Controllers
namespace App\Http\Controllers;

Related

Class 'app\login' not found in laravel 5.8

I am using laravel 5.8 and have an issue with model class. Since model is placed directly in app folder.
namespace App;
use Illuminate\Database\Eloquent\Model;
class Login extends Model
{
//
}
In Controller, I am using
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use app\Login;
use DB;
I initialized model class object in MyController.php as
$table_ob=new Login;
but facing this issue "Class 'app\Login' not found" when i submit form to controller.
It's minor spell mistake
use app\Login;
to
use App\Login;

Can't find new controller created

I everyone I've created a new Controler inside my App\Controllers\Admin folder and I already have two files called AdminInquiriesController and AdminUsersController.
When I run my app it says that
Class App\Http\Controllers\AdminNewsController does not exist
I don't undersantd. In all my 3 files inside this folder I'm using the namespace namespace
App\Http\Controllers
if it's working for the others why is not working for this?
<?php
namespace App\Http\Controllers;
use App\Manager\InquiryManager;
use Auth;
use Illuminate\Http\Request;
use function GuzzleHttp\json_decode;
use App\Model\InquiryStatus;
use Carbon\Carbon;
use App\Manager\UserManager;
class AdminInquiryController extends Controller {
<?php
namespace App\Http\Controllers ;
use Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Carbon\Carbon;
use App\Manager\NewsManager;
class AdminNewsController extends Controller {
In my route file..
// inquiries
Route::get('/admin/inquiries', 'AdminInquiryController#search');
// news
Route::get('/admin/news', 'AdminNewsController#search');
Route::post('/admin/news/new', 'AdminNewsController#create');
I know this is so silly but I'm not understanding what's happening...
You should to define namespace in your controller file;
namespace App\Http\Controllers\Admin ;
Also change your web.php route file to
Route::get('/admin/news', 'Admin\AdminNewsController#search');
Or you can define namespace in routes group by
Route::namespace('Admin')->group(function () {
Route::get('/admin/news', 'AdminNewsController#search');
}
Also you have to put
use App\Http\Controllers\Controller;
In your controllers files in Admin folder
Try to add a second forward slash when writing model location
something like this
--model=App\\Models\\ModelName

Class does not exist when up project to hosting

In localhost it runs ok, but when code is deployed to hosting there occurs an error in router/web.php. Code :
Route::get('about',"HomeController#index");
and in App\Http\Controllers\ I have file HomeController.php that contains:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Validator;
use App\TheLoai;
use App\LoaiTin;
use App\TinTuc;
use App\User;
use App\Slide;
use DB;
class HomeConTroller extends Controller
{
//...
But it throws this error:
Class App\Http\Controllers\HomeController does not exist
How can I fix it?
HomeConTroller - should be HomeController - only C is capital
Change the controller's name from HomeConTroller to:
class HomeController extends Controller
{
//
}
Then run this to terminal:
composer dumpautoload

ReflectionException in Route.php line 333: Method App\Http\Controllers\Auth\LoginController::mail() does not exist

Route details:-
Route::get('/email_id_exist','Auth\LoginController#mail');
Controller details
<?php namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
use App\Models\UserAdmin;
class LoginController extends Controller
{
public function mail(Request $request)
{
....Some code here... and returned back;
}
}
Controller path:-
....project_name\app\Http\Controllers\Auth\LoginController.php
Error is only shown on server which is linux based (Error displaying:), and on my windows local it is working properly.
Php version for server is 7.0.7 and on my local is 7.0.9
Please help
Solved it!
It was all because (ModelName::where('v_id',1)->count();) which was causing an error just added a space between 'v_id', 1 so (ModelName::where('v_id', 1)->count();) and it was solved. This worked for me, Thanks everyone for helping Cheers njy.

Laravel - Class/Model not found

Initially, this code worked, but it doesn't work anymore. I don't know what is causing the issue.
The error is :
FatalErrorException in AdminController.php line 64:
Class 'App\Category' not found
AdminController code is:
<?php
namespace App\Http\Controllers;
use Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use App\Category;
use View;
class AdminController extends Controller
{
public function article_get()
{
$categories = Category::latest()->get();
return View::make('create.article')->with('categories',$categories);
}
}
My model Category is located at App/Models/Category.php.
What I've tried:
Change from use App\Category; to use Category, to use \Category, to use App\Models\Category.
composer dump-autoload.
A few hours ago I had a working project, but now my models are not found.
Because Laravel uses PSR-4 autoloading, you need to make sure your namespaces match the real directory structure.
You say that your Category model is located at App/Models/Category.php so its namespace should be App\Models. Then, in your controllers you would use App\Models\Category.
I had also faced the same error when Models are called inside Controllers or Seeders.
The best solution is to import your Model inside the Controllers.
Add the below line at the top of your AdminController.
use App\Models\Category
This is applicable for all Classes where you try to call your models.
Do it like this and it must work:
use App\Models\Category
and make sure that the model Category is inside a folder named Models.
Your code seems fine.
May be it has an issue with namespace in Category model.
if you use this code for Category Model in your AdminController controller:
use App\Models\Category;
then your Category model itself has this namespace
namespace App\Models;
Check if your model namespace is still there or not.
Thanks
App\Models\Category
PLease Check This twoThings
1.Importing namespace App\Http\Controllers;
2,Check Controller Letter is in Upper Or LowerCase
like this
use App\models\Category----->❌❌❌
use App\Models\Category----->✅✅✅
use App\Models\Category
//check your models is capital or small letter sometimes issue like that is a big problem

Categories