So here I am on a Sunday, trying to make progress with a personal Laravel 5 site I need to work on. As I bear with the noise outside in the street (some crazy neighbors set up a swimming pool IN THE STREET! :oops:), I’m trying to figure out how too create a new Laravel 5 controller and place it inside a sub-folder.
Thanks to a StackOverflow answer as my guide, it’s now working. Here, I’ll share how I did it. Just replace “New” with whatever name you want.
First, create NewController.php on this folder: app\Http\Controllers\New\
Then the first part of the code should be like:
1 2 3 4 5 |
<?php namespace App\Http\Controllers\New; use App\Http\Controllers\Controller; class NewController extends Controller { |
My call for the blade file in index() looks like this:
1 2 3 4 |
public function index() { return view('admin.home'); } |
In app\Http\routes.php, add this:
$router->get(‘/new’, ‘New\PostsController@index’);
Last, run composer dump-autoload
or php artisan dump
Guide: Laravel Controller Subfolder routing