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
Related
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;
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
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;
I'm trying to use the laravel 5.3 mailable for email verification, but it's not working and returns me this error -
FatalThrowableError in RegisterController.php line 84:
Class 'App\Http\Controllers\Auth\Mail' not found
The top of the RegisterController.php looks like -
namespace App\Http\Controllers\Auth;
use App\Mail\VerifyEmail;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller
VerifyEmail is my mailable class generated using make:mail.
Line 82-84 of RegisterController.php -
$email = new VerifyEmail($verification_code);
Mail::to($data['email'])
->send($email);
The full stack trace is pasted here http://pastebin.com/r9sQpPdy.
Your problem is that you're trying to use the Mail facade in class that's in another namespace, without importing (use) it.
You either do:
\Mail::to($data['email'])
->send($email);
OR you should use it:
use App\Mail\VerifyEmail;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\RegistersUsers;
use Mail;
class RegisterController extends Controller
So I am new to laravel and was just trying out some code to clear the basics,but however after creating a new controller to handle a route.It throws a fatal exception saying Class 'Controller' not found!
(The controller.php exists in the same directory)
The controller.php code is the default one
<?php
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
abstract class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
}
This is my PagesController.php code
<?php
class PagesController extends Controller
{
public function home()
{
$name = 'Yeah!';
return View::make('welcome')->with('name',$name);
}
}
This is route.php code
<?php
Route::get('/','PagesController#home');
The welcome.blade.php code is the default one except it displays the variable $name instead of laravel 5.
What am I getting wrong?
When you reference a class like extends Controller PHP searches for the class in your current namespace.
In this case that's a global namespace. However the Controller class obviously doesn't exists in global namespace but rather in App\Http\Controllers.
You need to specify the namespace at the top of PagesController.php:
namespace App\Http\Controllers;
You will want to specify the namespace to your Controller class:
class PagesController extends \App\Http\Controllers\Controller
otherwise Controller is looked up in the default root namespace \, where it does not exist.
My issue was a different class name than the one in the class that extends controller, the names should be same
If you are creating a controller inside a subfolder with a different namespace then use this on your controller file:
use App\Http\Controllers\Controller;