Class 'App\Http\Controllers\DB' not found and I also cannot use a new Model
The problem here are PHP namespaces. You need to learn how to use them. As your controller are in App\Http\Controllers
namespace, if you refer any other class, you need to add leading backslash (or proper namespace) or add use
statement at the beginning of file (before class definition).
So in your case you could use:
$headquote = \DB::table('quotation_texts')->find(176);
$headquote = \App\Quotation::find(176);
or add in your controller class use
statement so the beginning of your controller class could look like this:
<?php
namespace App\Http\Controllers;
use DB;
use App\Quotation;
For more information about namespaces you could look at How to use objects from other namespaces and how to import namespaces in PHP or namespaces in PHP manual
Class 'App\Http\Controllers\DB' not found in Laravel 5 Controller
DB
is not in your current namespace App\Http\Controllers
. So you can either import it at the top
use DB;
or precede it with a backslash \DB::table(...)
. This solves the class not found exception.
You are however not getting a Laravel Collection of Employee models but an array of database rows. Arrays are not objects that have a count() function which results in your final error.
Update: Laravel 5.3 will return a Collection object and not an array. So count() will work on that.
Class 'App\Http\Controllers\DB' not found
Add use DB;
to your Controller.
Class 'App\Http\Controllers\Session' not found in Laravel 5.2
From the error message:
Class 'App\Http\Controllers\Session' not found
I see that Laravel is searching the Session
class in the current namespace: App\Http\Controllers
The problem is you don't have aliased the class from the global namespace: Session
is a Facade, and all the facades are in the global namespace
To use the class from the global namespace, put:
use Session;
on top of your controller, after your namespace declaration
Alternatively, you can call the class from the global namespace with:
\Session::get('panier');
Laravel Error Class 'App\Http\Controllers\DateTime' not found
Above your class definition, import the class with a use statement.
use DateTime;
The alternative to that is to use the fully qualified namespace in your code. With PHP classes in the global namespace, all this means is a single backslash before the class name:
$expires = new \DateTime('NOW');
I prefer the first approach, as it allows you to see every class used in that file at a glance.
laravel Class 'App\Categories' not found
Because models are autoloading via composer
in some cases you need to run composer dump-autoload
after changes in order to make it work
Related Topics
How to Enable Ssl in Wamp Server
How to Extract a String from Double Quotes
Format Output of $Simplexml->Asxml();
PHP Send Email with Attachment
Jquery Load() and PHP Variables
Does the Condition After && Always Get Evaluated
How to Strip Out the Domain Name from a Url in PHP
Bulletin Board - Database Optimisation
PHP File-Upload Using Jquery Post
What Is the Safest Way of Passing Arguments from Server-Side PHP to Client-Side JavaScript
How to Fix Warning from Date() in PHP"
How to Measure the Strength of a Password
How to Add a Watermark to an Existing PDF File Using PHP
How to Convert Between Time Zones in PHP Using the Datetime Class
Unit Testing with Items That Need to Send Headers