I'm using Laravel 5.2 and caffeinated Modules and I'm getting this error
NotFoundHttpException in RouteCollection.php line 161:
I only get this error when I upload to my server but on my localhost I don't get an error.
I've also noticed that on my localhost I get all my routes listed but on my server I only have the home page.
My Users Module route.php
Route::group(['middleware' => 'web'], function()
{
Route::get('admin/', [
'uses' => 'UsersController#showLogin',
'as' => 'login'
]);
Route::post('admin/', [
'uses' => 'UsersController#doLogin',
'as' => 'doLogin'
]);
});
and my Users Module UsersController.php
<?php
namespace App\Modules\Users\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class UsersController extends Controller
{
public function showLogin(){
echo "Users Controller";
}
}
If there is anything I've missed to help with this please let me know.
This error generally shown when you access a url which is not defined in your route file. Recheck the url you are trying to access.
Your code doesn't seem to have any special error.
Add a doLogin method in your UsersController.
Besides, you can try by removing / from the route path.
I mean change this:
Route::group(['middleware' => 'web'], function()
{
Route::get('admin/', [
'uses' => 'UsersController#showLogin',
'as' => 'login'
]);
Route::post('admin/', [
'uses' => 'UsersController#doLogin',
'as' => 'doLogin'
]);
});
to this:
Route::group(['middleware' => 'web'], function()
{
Route::get('admin', [
'uses' => 'UsersController#showLogin',
'as' => 'login'
]);
Route::post('admin', [
'uses' => 'UsersController#doLogin',
'as' => 'doLogin'
]);
});
I finally found the answer. I had to delete the /storage/app/modules.json and then I ran
php artisan module:optimize
Related
So my scenario is:
Route::group(['middleware' => 'api'], function ($router) {
Route::post('/login', [
'as' => 'login',
'uses' => 'App\Http\Controllers\Admin\CustomerCrudController#login',
]);
Route::post('/register', [
'as' => 'register',
'uses' => 'App\Http\Controllers\Admin\CustomerCrudController#register',
]);
Route::get('/logout', [
'as' => 'logout',
'uses' => 'App\Http\Controllers\Admin\CustomerCrudController#logout',
]);
});
Here Login API is working perfectly using postman but register and logout api's are returning 405 method not allowed error.
Note: I have already checked that I must be using post and get correctly. These API's were also working right previously. I don't know what has made them stop.
In case if someone wants to have a look at controller functions, here is the gist. Looking forward to the suggestions.
I'm learning laravel and I have a problem with my base url which is http://localhost/.
It keeps redirecting to http://localhost/home which is the base authentication route and since im not logged in, it redirects me to http://localhost/login.
I want http://localhost/ to redirect to http://localhost/blog/posts as it should.
I'm doing this because in the future the base url will redirect to another page. Until then, I want to display the blog posts.
web.php
Route::get('/', [
'as' => 'index',
'uses' => 'HomeController#index',
]);
Route::get('/blog/posts', [
'as' => 'blog',
'uses' => 'BlogController#index'
]);
Auth::routes();
Route::get('/home', [
'as' => 'home',
'uses' => 'HomeController#home'
]);
HomeController.php
public function home()
{
return view('home');
}
public function index()
{
return view('blog');
}
I hope I was clear enough, i'd be glad to give more info if needed.
Problem solved:
Comment or remove $this->middleware('auth'); in HomeController.php and add it in the route:
Route::get('/home', [
'as' => 'home',
'uses' => 'HomeController#home'
])->middleware('auth');
Check that the HomeController __construct() function doesn't have an auth middleware inside, that would try to log you in first, then continue to check for the index function.
I am building a modular application in laravel. I created a User module and here is the routes:
<?php
Route::group(['middleware' => 'web', 'namespace' => 'Modules\User\Http\Controllers'], function()
{
Route::get('/', 'UserController#index');
Route::get('login', 'LoginController#showLoginForm')->name('login');
Route::post('login', 'LoginController#login');
Route::post('logout', 'LoginController#logout')->name('logout');
});
Route::group(['middleware' => 'admin', 'prefix' => 'user', 'namespace' => 'Modules\User\Http\Controllers'], function()
{
Route::get('register', 'RegisterController#showRegistrationForm')->name('register');
Route::post('register', 'RegisterController#register');
});
The route('login') statement returns the url to login page and it works well. Inside the config.php I need to access this function as follows
<?php
return [
'name' => 'User',
'menu' => [
'weight' => 1,
'item' => [
'Login' => [route('login'), 'guest'],
'Register' => [route('register'), 'guest'],
]
]
];
Inside this file the error Route [login] not defined. is reported. Why is this undefined in there?
I also tried adding the following line
namespace Modules\User\Http\Controllers;
But it still not working
thanks
My named route group is working fine without resource route. But when I am trying to use 'resource route' then getting this error. Would someone help me please, in where I am doing wrong?
My Route Group is -
Route::group(['prefix' => 'admin', 'as' => 'admin.', 'middleware' => 'auth:admin'], function () {
Route::get('dashboard', array('as' => 'dashboard', 'uses' => 'Admin\AdminController#dashboard'));
Route::group(['prefix' => 'student', 'as' => 'student.'], function () {
Route::resource('admission', array('as' => 'admission', 'uses' => 'Admin\StudentController'));
}); });
You need to pass resource controller name as string as the second parameter for Route::resource():
Route::resource('admission', 'Admin\StudentController');
You don't need to specify routes names with 'as' => 'admission' because the Route::resource() will do that automatically.
After trying out this acl tutorial I came across something I can't understand.
In laravel I created my route according to the tutorial and changed it to match laravel's auth controller (as I already used that before by installing it with bestmomo) to:
$router->get('/', [
'uses' => 'Auth\AuthController#getLogin',
'as' => 'admin.user.login',
'middleware' => ['acl:login']
]);
Like this it doesn't find my route giving me the error
NotFoundHttpException in RouteCollection.php line 161:
If I add the following route:
Route::get('/login', [
'as' => 'login', 'uses' => 'Auth\AuthController#getRegister'
]);
It works well.
Why do I need to add the second route?
Why can't the first one stand alone?
I think the blog you are following has an error.
The correct way to call a route you need is:
Route::get('/', [
'uses' => 'Auth\AuthController#getLogin',
'as' => 'admin.user.login',
'middleware' => ['acl:login']
]);
Note: you can also use a helper method and just call:
get('/', [
'uses' => 'Auth\AuthController#getLogin',
'as' => 'admin.user.login',
'middleware' => ['acl:login']
]);;
The only way I can see the the code you mentioned working is if the following is at the top of the routes file:
$router = app('router');