Laravel 5.4.36 - Deleted controller now having problems - visual-studio

I created a second controller in an attempt to imitate a PostsController I learnt off the Laravel From Scratch tutorial on YouTube in order to try and change the redirect folders in the public function etc to a different view's folder and see what happens but it was clashing with the original controller so I ended up deleting it along with its route::resource code.
Now when I try to go back to my original "Posts" page in the browser i get an ErrorException reading:
include(C:\wamp64\www\lsapp\vendor\composer/../../app/Http/Controllers/ShowsController.php): failed to open stream: No such file or directory
I imagine this is a composer issue and wondering if I could get some insight on how to fix it! Thanks

So I figured it out and all I had to do is run the composer dump-autoload command in the integrated terminal.
fixed!

Related

Target class [UsersController] does not exist

I am trying to load up a view, as simple as that. I don't know where to go I using composer dump-autoload that it was an issue with loading the controller however it didn't help.
The pictures show the project filesRoutes file
Controller
View
Error
I'm hoping to get some help!
If you are using laravel 8 you should pass controllers in routes in new way. This syntax which you try is the old one. Check this..
use App\Http\Controllers\UserController;
Route::get('/users', [UserController::class, 'index']);
Also you should follow convention and name your controllers in singluar form. user not users. Let me know if it helped.

Laravel Class Controller not found because route is weirdly case sensitive

I wanted to add a controller to an already existing project of mine. Wrote a controller file, added the link in the admin_api route file and adjusted the view I needed.
On my local machine everything works fine.
On production it failed (it's supposed to retrieve a collection, which is then handled and displayed by a vue js component) and the network monitor showed an error 500.
I ssh into the website and ran php artisan route:list which gave me the error
In Container.php line 779:
Class App\Http\Controllers\Admin\Api\StatsController does not exist
Although the file StatsController is in App\Http\Controllers\Admin\API\
After playing around I realized that the problem was with the folder name "API", as laravel was looking for "Api". So apparently it's case sensitive.
Placing the controller in a new folder "Api" solved the issue.
Moving all the other "API" controllers to "Api" broke their routes.
when running php artisan route:list and in RouteServiceProvider all routes appear as under Admin/Api.
What I don't get is where is this being registered? Is there a way to change this?
I find it quite annoying that the controllers sit now in separate folders and it seems quite absurd to me. I don't quite get how the original controllers worked if they seem to contradict the other configurations.
Working with Laravel 5.7
I would appreciate any insights!
Thanks
Just put all the relevant api controllers in a folder named Api or API (just pick a convention and stick with it), then make sure that each file's namespace (declared at the top) is correct and reflects the folder structure you have chosen.
For example, if your controllers are in app/Http/Controllers/Admin/Api, check that each controller file begins with:
<?php
namespace App\Http\Controllers\Admin\Api;
// Rest of code...
StatsController.php must have the namespace as App\Http\Controllers\Admin\API. In Controller.php you have to import as App\Http\Controllers\Admin\API\StatsController. After that, run composer dump-autoload

Laravel using wrong controller

Laravel generates same controller in console directory and when i render dashboard component then laravel use controller from console directory which is wrong. So if I make changes in controller then its not reflecting.
After delete controller from console directory and then fire the composer dump-autoload its solved my issue

Laravel showing blank page

I just setup a Laravel 5 framework in my server by typing in terminal
laravel new blog (in "/var/www/html/" folder),
then changed the default config of Nginx so the root pointing to : root /var/www/html/blog/public;
of-course all the files are in place however I currently just see a blank page showing up ! I tried to put a html & PHP file in public folder and it all works fine. but not Laravel default index file. what am I missing here ?
For adding pages in Laravel you do not simply put files in /public. Please have a look at the official Laravel page if you want to create new views.
Laravel uses the MVC principle. So you need to have at least a view (the part which is displayed) and a controller which handles the view. To add a new Controller, please change to the project root cd /var/www/html/blog and type in php artisan controller:make AwesomeController which creates the controller in app/Http/Controllers/AwesomeController.php.
In this Controller you can simply return a view by adding return view('myview') to the index() Method for example. (The view has to exist at resources/views/myview.blade.php of course)
In the last step you need to tell Laravel how to call your controller. Please modify the routes.php file at app/Http/routes.php and add Route::get('foo', 'AwesomeController');. Now you need to tell composer that some of your controllers may have changed and composer needs to refresh the cache. Type in composer dump-autoload and start the development server php artisan serve.
By calling http://localhost:8000/foo (by default) you should see your View. Have a nice day!

laravel returning blank screen in production environment

I built a laravel application and uploaded via FTP
Its showing blank in cPanel hosting
I moved the laravel files to another folder and moved all "public" files to public_html folder
I made the app/storage flder writable.
After everything, it shows blank screen
I remember encountering this White Screen Of Death in one of my first attempts at Laravel. It was a permission issue. To avoid duplicate threads, here's a link outlining the issue and solution: Laravel Migration Showing Blank Page, No Debug Screen
Did you debugged if you get any output, for example try adding this to your routes.php file:
Route::get('/', function() {
dd('hi');
});
For Lavarel 4.2, this could also help:
php artisan optimize

Resources