Class 'App\Modules\Users\UsersServiceProvider' not found - php

I am trying to work in HMVC architecture; i am working in laravel 4.2.
I install the HMVC of laravel but got some problem.
Class 'App\Modules\Users\UsersServiceProvider' not found
Above error occurred while putting following code in module.json
{
"enabled": true,
"provider": [
"App\\Modules\\Users\\UsersServiceProvider"
]
}
and UsersService Provider is as follows:
<?php namespace App\Modules\Auth;
class UsersServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
\Log::debug("UsersServiceProvider registered");
}
}
While I remove the provider section in module.json it works fine; but have another problem.
View can not be loaded from corresponding views folder and I wrote the route as follows: (here controller works fine)
Route::get('users',array('uses'=>'UserController#getIndex'));
<?php
class UserController extends BaseController{
public function getIndex(){
echo 'Yes this works.';
return View::make('users::users');
}
?>
echo 'yes this works'; // works fine
while i moved to next line of code it always in the search of Views folder if users file is not in main view then it generates error.
Can anybody tell me, whats wrong with my code; guide me to have correct way to do things in HMVC, so that i can getting things done.

Your .php class says its in the "App\Modules\Auth"
While the .json is looking in the namespace: "App\Modules\Users"
So you have to change one to the right namespace.

Related

InvalidArgumentException - No hint path defined

I am trying to add controller view in my existing project that consider model view controller structure in php with laravel.
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata::create');
}
}
When I implement this, it shows me error for,
InvalidArgumentException
No hint path defined for [CashFlowdata].
I have added file in route.php and web.php as added other controller data. Only for this one it shows message like this.
you code is wrong you should to something like this
class CashFlowdataController extends Controller {
public function index() {
return view('CashFlowdata.create');
}
}
here CashFlowdata.create
its means in laravel
folder structure should be
view>CashFlowdata>create.blade.php
laravel view() function is a helper to load view file
ref link https://laravel.com/docs/8.x/helpers#method-view
I had the same issue in nwidart/laravel-modules due to module.json file was miss place.
I move the file to the root of module now working fine.

Codeigniter loading model from different subfolder

I'm facing one weird problem with my Codeigniter project.
I have two model files in the following paths:
models/public/Dish_model.php
models/admin/Dish_model.php
For front-end and back-end models respectively.
In the controller which is in the following path:
controllers/admin/Dish.php
I'm trying to load the admin area model file using:
$this->load->model('admin/dish_model');
But it is loading the public model file.
Even if I comment this line out the public model file still gets loaded.
This all happened suddenly it was working fine before and I haven't changed any of the mentioned files recently.
Any help?
In case anyone else encounter the same issue.
In my case and after carefully following the execution path of the controller I found that the other model was being loaded by a library in the autoload list.
Removing that library from the autoload array fixed the problem.
to call/load a model from its subdirectory or subfolder.
models/public/Dish_model.php
let's say in Dish_model
class Dish_model extends CI_Model{
public function __construct(){
parent::__construct();
}
public function the_method(){
return 'return value';
}
}
models it's a native ci model directory and public it's a subdirectory. so to load the Dish_model do this on controller
$this->load->model('public/Dish_model','DModel');
the DModel it is like an alias.
so to call the model from the controller is
echo $this->DModel->the_method();
and it will return return value
hope its help.

How can I correctly setup models in Laravel 5 and fix my error?

I am currently learning Laravel 5. I have connected my database. Setup routes, created a controller, created a view and attempted a model, which is where I need help.
I used php artisan to create my model, which is in the /app directory.
When I try to visit /myer on the browser. I am getting the following error:
FatalErrorException in MyersController.php line 20:
Class 'App\Http\Controllers\Myer' not found
I have put the edited files on http://www.filedropper.com/help
I have no idea where I have gone wrong, I have messed around using "use" and ultimately all I get is that the Class can't be found. This is beginning to destroy my soul. If someone can help me, I would be forever grateful!!
Files
From MyersController.php
public function index()
{
$myers = Myer::all();
return view('myers.index')->with('myers'.$myers);
}
From routes.php
Route::get('/myer/', 'MyersController#index');
Route::resource('myer','MyersController');
From Myer.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Myer extends Model
{
//
}
From index.blade.php
<h2>Myers</h2>
<ul>
#foreach ($myers as $list)
<li>{{{ $list->name }}}</li>
#endforeach
</ul>
As you can see in the error, it tries to find the model in the same namespace as your controller: FatalErrorException in MyersController.php line 20: Class 'App\Http\Controllers\Myer' not found. In the Model, you can see it's in namespace App.
So either put
use App\Myer;
in the top of your controller under the namespace, or reference the full path where you need it:
public function index()
{
$myers = App\Myer::all();
return view('myers.index')->with('myers'.$myers);
}
But if you will use it more often in this controller, then it's more efficient to put it in the use.
P.S. Please don't let it destroy your soul.

Laravel Controller doesn't exist, even though it clearly exists

The error I'm getting is that the controller doesn't exist even though I know it does, here's the code.
Route.php
Route::get('mdpay/template', array("uses" => "templateController#index"));
templateController.blade.php
class templateController extends BaseController {
public function index()
{
echo "made it";
}
}
Why might I be getting this error: Class TemplateController does not exist
================= UPDATE: ==================
Ok, so I've created the correct route, renamed my file, and corrected the class name and I'm still coming up with that error.
File Names:
templateController.php
// File Name: TemplateController.php
class TemplateController extends BaseController {
public function index()
{
// app/views/myView.blade.php
echo "hello";
}
}
My route is:
Route::get('mdpay/template', array("uses" => "TemplateController#index"));
Still receiving Controller Doesn't Exist error. All my other controllers (3 others) are working except this one.
If you are using the standard composer classmap autoloader you need to composer dumpautoload everytime you create a new file.
So to create a new controller with the standard composer setup given by Laravel:
Create a new file in app/controllers named TemplateController.php
Open up terminal and run composer dumpautoload
As previous users have said, only view files should end with .blade.php.
If you're using Laravel 8, add this line to your RouteServiceProvider.php (you can search it by using CTRL + P):
protected $namespace = 'App\Http\Controllers';
This solved the issue for me.
It should be:
// File Name: TemplateController.php
class TemplateController extends BaseController {
public function index()
{
// return "made it"; // or
// app/views/myView.blade.php
return View::make('myView');
}
}
Route for that:
Route::get('mdpay/template', array("uses" => "TemplateController#index"));
Use blade in a Blade view, i.e: myView.blade.php basically stored in app/views/ folder. Read more about blate template on Laravel website.
Controllers live in the app/controllers directory and should remain there unless you have your own namespaced structure.
The reason you're getting a Class TemplateController does not exist is because it doesn't, firstly, your class is called templateController and secondly, it exists as templateController.blade.php which wouldn't be loaded in this way.
Blade files are for views, and only views within app/views or a custom views directory should end with .blade.php.
Create the file app/controllers/TemplateController.php and add the following code to it.
class TemplateController extends BaseController {
public function index()
{
echo "made it";
}
}
Now on the command line, run the command composer dumpautoload and change you route declaration to:
Route::get('mdpay/template', array('uses' => 'TemplateController#index"));
Now it should all work.
In case you're using Laravel 9 and the error is like Illuminate\Contracts\Container\BindingResolutionException and Target class <controller name> does not exist. when trying php artisan route:list on terminal.
This is the setup that I do:
Add protected $namespace = 'App\\Http\\Controllers'; to RouteServiceProvider.php
Add 'namespace App\Http\Controllers;' to the controller file.
Do php artisan optimize on terminal
(Just to make sure the route already there) Do php artisan route:list again on terminal, and the controller route should be displayed.

Laravel Controller in Folder - Routing doesn't work

I am putting my Controller called "LoginController" in a folder "login".
class LoginController extends BaseController{
public $restful = true;
//log in function
public function Login(){
// load the login page
return View::make('login.login');
}
}
In the routes, I give this:
Route::get('/',array('uses'=>'login.LoginController#Login'));
Also tried
Route::get('/',array('uses'=>'login\LoginController#Login'));
Route::get('/',array('uses'=>'login\Login#login'));
None of the above seem to work, and give me Class does not exist error.
I am very dumbstruck with this error. Is the way I am accessing the controller in the "uses" correct? Do I need to do any additional things before I can get it to work?
Any help really appreciated!
All you should need is
Route::get('/',array('uses'=>'LoginController#Login'));
Composer need to register this change in routes so dump-autoload composer
php composer.phar dump-autoload
Also if you are using laravel 4, then declaring restful controllers with
public $restful = true;
no longer works.
this happens to me often, just to give a different answer that worked for me
php artisan dump-autoload
Enjoy!
Yeah i had the same issue, i got my answer from https://stackoverflow.com/a/31638718/2821049
Route::group(['namespace' => 'login'], function(
{
// Controllers Within The "App\Http\Controllers\login" Namespace
Route::get('/','LoginController#login');
});
In class you adds :
namespace App\Http\Controllers\folder;
use App\User;
use App\Http\Controllers\Controller;
and in routes you call:
Route::get("admin/login","folder\class#NameFunctionInClass");
Note: folder is the name folder class contains

Categories