My app structure is this:
app
-- http
-- -- controllers
-- -- -- Admin
-- -- -- -- ExampleController.php
-- ExampleModel.php
My controller:
namespace App\Http\Controllers\Admin;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ExampleController extends Controller {
My model:
namespace App;
use Illuminate\Database\Eloquent\Model;
class ExampleModel extends Model {
My Error:
Class 'App\Http\Controllers\Admin\ExampleModel' not found
What would be the correct namespace for the following structure?
I think you should do
use App\ExampleModel;
in your controller
namespace App\Http\Controllers\Admin;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
**use App\ExampleModel;**
class ExampleController extends Controller {
Related
DosenController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Models\Dosen
Dosen.php
<?php
namespace App;
namespace App\models;
when I changing use App\Models\Dosen; to App\Dosen;, but Class 'App\Dosen' is not found
First you have two namespace in your model
namespace App;
namespace App\models;
and second in your controller you have used Capital M .But in model you have small letter m.
so you should correct Dosen.php.First remove both namespace in Dosen.php and add it like below
<?php
namespace App\Models;
To Avoid namespace issue in you model.You can create model using php artisan command
php artisan make:model Dosen
Ref:https://laravel.com/docs/7.x/eloquent#defining-models
you have to remove the first namespace
<?php
namespace App;
then change the namespace to namespace App\Models;.
after these changes you can use your model inside your controller
in Laravel7 , Models was in App Folder , so :
DosenController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Dosen; // edit this line
Dosen.php
<?php
namespace App;
// namespace App\models; // remove this line
I got the message : Class 'App\Http\Controllers\Auth\RouteServiceProvider' not found
Class in Verify controller
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Auth;
use Nexmo;
use App\Providers;
use User;
Calss in Longin Controller
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Validator;
use App\Http\Controllers\Redirect;
use App\Http\Requests;
use Nexmo;
use App\Providers;
How do you solve class problems?
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;
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
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