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
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
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
This question already has an answer here:
Class 'App\Http\Controllers\admin\Auth' not found in Laravel 5
(1 answer)
Closed 10 months ago.
I'm trying to implement Socialiate for Laravel 5.5 using this guide https://scotch.io/tutorials/laravel-social-authentication-with-socialite. Data is returned properly from the provider, but I am having trouble defining Use and Namespaces.
With this configuration:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Socialite;
The result is:
Class 'App\Http\Controllers\Auth\User' not found
Triggered by:
$authUser = User::where('providerId', $user->id)->first();
But, if I add App\User:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\User;
use Socialite;
The result is:
Class 'App\Http\Controllers\Auth\Auth' not found
Triggered by:
Auth::login($authUser, true);
Any help is much appreciated.
You didnt import Auth namespace the right way.
The proper namespace is Illuminate\Support\Facades\Auth;
Add use Illuminate\Support\Facades\Auth; at the top of your class.
Try Also, adding use App\User;
namespace App\Http\Controllers\Auth;
use Socialite;
use App\User;
in my case help came when i see that included files were only user and not the socialproviders table in the name space i use two tables Users and Social_providers .. it took 2 days to resolve eaten 4 gb data.
enter code here
namespace App\Http\Controllers\Auth;
use Socialite;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\Models\User;
use App\Models\socialProvider;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
//use Laravel\Socialite\Facades\Socialite;
class RegisterController extends Controller
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 {