Is it possible to call a control that is nested within a sub folder in Laravel 4?
My Controllers are as follows
- Controllers
- admin
* AdminController.php
* HomeController.php
* BaseController.php
* ArticleController.php
Below is the code from my AdminController class:
<?php
class LoginController extends BaseController {
public function showLogin()
{
return View::make('partials.admin.login');
}
}
In my Routes.php file I am doing the following:
Route::get('/admin', 'admin.LoginController@showLogin');
But I'm getting a Class not found error. Is there anything I'm missing as I can't seem to find out how to solve this problem from the Laravel 4 documentation.
As long as you don't change the namespace of the controller you should be able to access it from the global namespace even if it is in a subfolder.
So just change:
Route::get('/admin', 'admin.LoginController@showLogin');
to:
Route::get('/admin', 'LoginController@showLogin');
The filename also needs to match the class name so change 'AdminController.php' to 'LoginController.php' or change the class name from 'LoginController' to 'AdminController'.
And make sure you do composer dump-autoload
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With