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');
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 have this code
Route::get('posts/{id}/postedit','PostController#postedit');
Route::post('posts/{id}/postupdate','PostController#postupdate');
Route::get('posts/{id}/postdelete','PostController#postdelete');
Route::get('/{slug}', [
'uses' => 'SiteController#singlepost',
'as' => 'site.single.post'
]);
Route::get('/{id}', [
'uses' => 'PendaftaranAlumniController#test',
'as' => 'test',
]);
so here is the problem, when i run like this it Route::get('/{slug}' it works fine but Route::get('/{id}' it doesnt work
otherwise when i put Route::get('/{id} in the top it works fine, but Route::get('/{slug}' doesn`t work anymore.
how can i solve this?
Because both /{slug} and /{id} is getting treated as same by Laravel, both the routes /{slug} and /{id} will point any route defined earlier.
You can use it as it is, you need to tell Laravel that these two routes are different in any manner so that Laravel will treat it differently.
Route::get('singlepost/{slug}', [
'uses' => 'SiteController#singlepost',
'as' => 'site.single.post'
]);
Route::get('test/{id}', [
'uses' => 'PendaftaranAlumniController#test',
'as' => 'test',
]);
Which is valid way in laravel 5.7 to run several urls on the same control action, like
Route::get('about', array(
'as' => 'page-about',
'uses' => 'PageController#page_content'
))->AdditiveParameter('about');
Route::get('security', array(
'as' => 'page-security',
'uses' => 'PageController#page_content'
))->AdditiveParameter('security');
and In PageController page_content action have 1 required parameter ?
Thanks!
I am not sure if you are looking for this only, but hope it will give some idea.
Route::group(['prefix' => '{prefix?}', 'where' => ['prefix' => 'content']],function (){
Route::get('{route_name}/{req_param}', array(
'as' => 'page-security',
'uses' => 'PageController#page_content'
))->where('route_name', '(about|security)');
});
And Controller action will be something like this
public function page_content($route_name,$req_param)
{
}
Let me know if this is working for you.
1. Route::get('/admin', [
'uses' => 'AdminController#admin',
'as' => 'admin' ]);
2. Route::get('/{uri}', [
'uses' => 'ArticleController#article',
'as' => 'article' ]);
if I try to go to admin route it goes to article route, I need a solution for both routes to work.
The conflict arrives in your case due to /{uri} matches to /admin ,
For example. /xyz, /abc and even /admin match to /{uri} route.
You can do something like this to avoid it.
Route::get('/admin', [ 'uses' => 'AdminController#admin', 'as' => 'admin' ]);
Route::get('/uri/{uri}', [ 'uses' => 'ArticleController#article', 'as' => 'article' ]);
Note that now /admin will match to your /admin route and /uri/{parameter} will match to your /uri/{uri} route
You have to write route 1 first then route 2
Follow: Laracasts
Is it possible to redirect the user to a POST route in Laravel if validation fails?
Route::get('/order/confirm', ['middleware' => 'auth', 'uses' => 'PageController#orderConfirm']);
Route::post('/order/create', ['middleware' => 'auth', 'uses' => 'PageController#orderCreate']);
Route::post('/order/store', ['middleware' => 'auth', 'uses' => 'PageController#orderStore']);
I have 2 forms. First is confirm the order. Second is form containing the order.
If I give incorrect data in the order, shows an error message.
MethodNotAllowedHttpException in RouteCollection.php line 219:
PS: I'm sorry for my english.
Could you change
Route::post('/order/create', ['middleware' => 'auth', 'uses' => 'PageController#orderCreate']);
to
Route::get('/order/create', ['middleware' => 'auth', 'uses' => 'PageController#orderCreate']);
it will work.