PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] Laravel : Class controller does not exist

 January 19, 2022     laravel, laravel-5.5     No comments   

Issue

I have created a simple controller and define a function. But when i run this it returns an error that controller does not exist.

In my web.php assign a route.

<?php
  Route::get('/', function () { return view('front.welcome'); });
  Route::get('plan','PlanController@PlanActivity')->name('plan');

On otherside in my controller my code:

<?php
 namespace App\Http\Controllers\Front;
 use App\Http\Controllers\Controller as BaseController;
 use Illuminate\Http\Request;

class PlanController extends Controller {

public function PlanActivity()
{
    dd("hello");
    //return view('admin.index');
}
}

This controller created on App\Http\Controllers\Front - on front folder

Error :

ReflectionException (-1) Class App\Http\Controllers\PlanController does not exist


Solution

Add Front part to:

Route::get('plan', 'Front\PlanController@PlanActivity')->name('plan');

Also, change the top of the controller to:

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

And run composer du.

From the docs:

By default, the RouteServiceProvider includes your route files within a namespace group, allowing you to register controller routes without specifying the full App\Http\Controllers namespace prefix. So, you only need to specify the portion of the namespace that comes after the base App\Http\Controllers namespace.



Answered By - Alexey Mezenin
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing