Why am I getting Target class [Controller Name] does not exist - laravel

I always have this message:
Illuminate\Contracts\Container\BindingResolutionException
Target class [MessagesController] does not exist.
On some route and URL requests,
MessagesController however is not contained on my route web files, and in any of my controllers.
Can someone explain to me why the Controller class gives a warning?
Target class [MessagesController] does not exist.
Follow-up question, is there a way I can remove an unused controller by an artisan command?

The solution I made for this is to import MessagesController class, I'm so dumb I didn't figured it out.
On route:
use App\Https\Controller\MessagesController;

Related

findOrFail() method not found by PhpStorm

PhpStorm does not found findOrFail() method. When I try to call it, there isn't auto-complete and the result is always fail. The user found is always on the message.
I try to use Laravel Ide helper and query()->findorfail but I didn't resolve.
The result:
in phpstorm try the Laravel plugin to generate the IDE classes.
please check your User model. It must extend Model class like this.
use Illuminate\Database\Eloquent\Model;
class Lead extends Model {
I guess your User model is missing this "extends Model".
As I know, PHPStorm never detects the findOrFail method even we already installed the Laravel plugin.
But you use it wrong because this method takes an id and returns a single model. If the method can't find any matching data, it will return an error.
You can change the method into:
User::findOrFail($user->id);

How to attach middleware to an existing named route from a package in laravel 5?

I'm trying to extend an existing application without modifying its source code.
The application has a named route called wizard-add.
Is there a way to register \MyPackage\MyMiddleware with the existing route?
I tried attaching it via Route::getRoutes()->getByName('wizard-add')->middleware(\MyPackage\MyMiddleware::class); but since packages are registered before the routes are read, Route::getRoutes() returns an empty collection.
Thank you!
Since I didn't find a way to solve this, I extended the app's controllers and put my logic inside.
namespace MyPackage\Controllers;
use App\Controllers\WizardController;
class MyPackageWizardController extends WizardController { ... }
and then in my service provider's register() method:
$this->app->bind(WizardController::class, MyPackageWizardController::class);
So everytime the app attempts to instantiate WizardController, it instantiates MyPackageWizardController instead. I don't know if there are any drawbacks but so far this has been working perfectly for me.

Laravel 5.7, Moved User class, RegisterController can't find it

I am planning a somewhat complex Laravel application, and so I have moved the default User.php class from App\User to App\Http\Models\Users\User.
Paths & Code
I have changed the paths appropriately in the code (please see screenshot).
Unfortunately, I am still getting this error:
error message
I have not changed composer.json, nor any other files than config/auth.php and app/Http/Controllers/RegisterController.php. Also, I am unable to locate any other files in the project that are using App\User (other than RegisterController).
I have updated and migrated the file for the users table.
I'm probably missing something obvious, so please be kind. ;-)
Can someone point out what I'm missing?
The path must coincide with the namespace to the file be loaded as expected.
So if your path is
app\Http\Models\Users\User.php
Your class namespace must be:
namespace App\Http\Models\Users;
Note that the App on the namespace must be in CamelCase. Otherwise it will not work.
only 4 files contains App\User class reference
app/Http/Controllers/Auth/RegisterController
config/app.php
config/services.php
database/factories/UserFactory.php
The namespace in my User class was incorrect (missing 'Http'):
Wrong: namespace App\Models\Users
Right: namespace App\Http\Models\Users
Thank you all for your suggestions, especially #elias-soares!

Zend 2 - Default Controller route (ZF2)

I'm working on a website that have virtual hosts, like xyz.com, asd.com and so on.
I use Hostname route like ":controller.com", so it routes me to the specific controller.
I created a defaultController to a default behavior and I extended xyzController and asdController from that, so I only modify that I really want.
The problem is that, how can I create my DefaultController to be really default :) I mean, if I haven't created a controller for the specific route (forexample: xyzController for xyz.com), then I don't want to get a Fatal Error like
"Fatal error: Class 'aaaa\Controller\asdController' not found in /var/www/samba/aaaa/www/src/site/vendor/ZF2/library/Zend/ServiceManager/AbstractPluginManager.php on line 177"
Would be better if it route me to defaultController immediately.
I was thinking about the view_manager's templates like 'not_found_template'. That would be great if not_found_controller would exist :)
Is it possible to do somehow?

PHPUnit + CodeIgniter multiple objects with same name

I currently test my CodeIgniter app with phpunit by using CIUnit (https://bitbucket.org/kenjis/my-ciunit). The problem is that I have multiple controllers with the same name. I have a controller in the root controller directory named "Blog" and I have a controller called "Blog" in the controller/ajax/ directory.
The reason is to seperate all ajax requests from the main controller.
When I am running tests on both files, I get the following error:
PHP Fatal error: Cannot redeclare class Blog in ...
Well, I am not suprised I am getting this error.
What are my options to resolve this?
Prefix controllers in ajax directory with "ajax" (looks only a bit stupid url/ajax/ajax_blog)
Use namespaces (I guess I need to namespace codeigniter too then)
Create 3 seperate phpunit.xml files
This aren't really solutions I am looking for. Do I have any other options? Is it somehow possible to run each testsuite seperatly, but still in one command? Can I "clean" objects between testsuites? Anything else?
There are no other options except those you mentioned, as it is impossible to "unload" class definitions in PHP.
Naming two controllers the same is not a problem when you run CI normally, since only one controller is instantiated per request, but something that should be avoided.
If it is just the ajax-url you don't like, maybe override it in a route (in config/routes.php):
$routes['ajax/blog'] = 'ajax/ajax_blog';

Resources