i just want to group all my admin routes in my laravel. I'm a beginner in laravel and i want to synchronize all my admin routes in one group, my question is, why i cant put the post route inside the group of my admin routes?
Here is my routes:
Route::group(['as' => 'admin::', 'prefix' => 'admin'], function () {
Route::get('login', [
'as' => 'login',
'uses' => 'admin\AdminLoginController#index'
]);
Route::post('login', 'admin\AdminLoginController#auth')->name('admin.login');
});
my above code was returning error , where laravel says admin.login route doesn't exist. Then i tried to put the post route outside the group and it works. Why?.
Here is the code where returns no error:
Route::group(['as' => 'admin::', 'prefix' => 'admin'], function () {
Route::get('login', [
'as' => 'login',
'uses' => 'admin\AdminLoginController#index'
]);
});
Route::post('login', 'admin\AdminLoginController#auth')->name('admin.login');
Because you use as in your route group and it's admin:: and you may link to admin.
Now it goes to admin::login and you need admin.login
Related
I create a route resource which is inside in route group. But when I call this resource route in blade template it's show me Route not defined. What should I do. I am using Laravel 5.5.
My Route is..
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function(){
Route::get('dashboard', ['as' => 'dashboardRoute', 'uses' => 'DashboardController#index']);
Route::resource('categories', 'CategoryController');
});
My blade view is..
<div id="2" class="collapse">
Category
</div>
Error is..
Route [admin.categories.index] not defined. (View: D:\XAMPPP\htdocs\dynamic_blog\resources\views\admin\sidebar.blade.php) (View: D:\XAMPPP\htdocs\dynamic_blog\resources\views\admin\sidebar.blade.php) (View: D:\XAMPPP\htdocs\dynamic_blog\resources\views\admin\sidebar.blade.php)
Add the as index to the route group, that should prefix it with admin.
Route::group(['prefix' => 'admin', 'middleware' => 'auth', 'as' => 'admin.'], function(){
Route::get('dashboard', ['as' => 'dashboardRoute', 'uses' => 'DashboardController#index']);
Route::resource('categories', 'CategoryController');
});
Your routes are most likely cached.
Run
php artisan route:clear
to clear the route cache.
I defined two different guard in auth.php file like this :
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'website' => [
'driver' => 'session',
'provider' => 'websites',
]
]
There is two different section routes in web.php routes. one for website admn and another for normal users that is a member of those websites. like this :
Route::prefix('/website/{website}')->middleware('auth:website')->group(function () {
Route::group(['prefix' => 'banner_ads'], function () {
Route::get('banner_adsDatatable', ['as' => 'banner_adsDatatable', 'uses' => 'BannerAdsController#banner_adsDatatable']);
});
Route::resource('/banner_ads', 'BannerAdsController');
Route::prefix('/member/{member}')->middleware('auth:web')->group(function () {
Route::group(['prefix' => 'banner_ads'], function () {
Route::get('banner_adsDatatable', ['as' => 'banner_adsDatatable', 'uses' => 'BannerAdsController#banner_adsDatatable']);
});
Route::resource('/banner_ads', 'BannerAdsController');
});
});
Problem is that I have a resource controller (banner ads) that is shared with to users (website admins and members). As you can see I must to add it twice time.
But beacause for normal user I defined banner ads controller again, when I call banner_ads.update for example always return unAuthenticated user.
I do not know what can I do for solve this problem.
Seems like your auth:web middleware is inside auth:website. This is basically checking for an authenticated admin who is trying to access routes of an authenticated user.
You are trying to access routes as a normal user. So it is not working. Just replace your code with this:
Route::prefix('/website/{website}')->middleware('auth:website')->group(function () {
Route::group(['prefix' => 'banner_ads'], function () {
Route::get('banner_adsDatatable', ['as' => 'banner_adsDatatable', 'uses' => 'BannerAdsController#banner_adsDatatable']);
});
Route::resource('/banner_ads', 'BannerAdsController');
});
Route::prefix('/member/{member}')->middleware('auth:web')->group(function () {
Route::group(['prefix' => 'banner_ads'], function () {
Route::get('banner_adsDatatable', ['as' => 'banner_adsDatatable', 'uses' => 'BannerAdsController#banner_adsDatatable']);
});
Route::resource('/banner_ads', 'BannerAdsController');
});
I want to create dynamic route name for my app. Here is my route file
Route::group(['prefix' => '{team}/dashboard', 'middleware' => 'isMember'], function() {
Route::get('/user', array('uses' => 'UserController#index', 'as' => 'user.index'));
Route::get('/user/edit/{id}', array('uses' => 'UserController#edit', 'as' => 'user.edit'));
Route::patch('/user/{id}', array('uses' => 'UserController#update', 'as' => 'user.update'));
Route::delete('/user/{id}', array('uses' => 'UserController#destroy', 'as' => 'user.delete'));
it's not simple if i have to define route like this
'route' => ['user.delete', $team, $user->id]
or
public function destroy($team,$id) {
// do something
return redirect()->route('user.index', $team);
}
I want to generate route name like "$myteam.user.delete" or something more simplier like when i define "user.delete" it includes my team name.
How i can do that? is it possible?
You could do that by setting as. Also using resource routes will be handy.
$routeName = 'team.';
Route::group(['as' => $routeName], function(){
Route::resource('user', 'UserController');
});
Now you can call like
route('team.user.index');
More on resource routes here https://laravel.com/docs/5.3/controllers#resource-controllers
try this:
Route::delete('/user/{team}/{id}', array('uses' => 'UserController#deleteTeamMember', 'as' => 'myteam.user.delete'));
Now call the route as:
route('myteam.user.delete', [$team, $id]);
I'm trying to implement a simple CMS with Laravel 5.2 which basically handles two kinds of routes. The first one is used to browse a website view, that has to be {view}.html. The controller iterates the database records and if it can't find that page, will return a 404 error page:
Route::get('/{page}', [
'as' => 'page',
'uses' => 'Website\WebsiteController#showPage'
])->where(['page' => '.+(\.html)']);
For example these routes will match:
www.mydomain.ext/homepage.html
www.mydomain.ext/about.html
www.mydomain.ext/news.html
www.mydomain.ext/contact.html
and so on. The second one is a route group for the admin control panel:
Route::group([
'prefix' => env('ADMIN_PREFIX', 'admin'),
'as' => env('ADMIN_PREFIX', 'admin') . '::',
'middleware' => ['auth']
], function() {
/*
* ADMIN ROUTES
*/
});
So all the routes in this group will be something like:
www.mydomain.ext/admin/dashboard
www.mydomain.ext/admin/user/1
www.mydomain.ext/admin/page/2
and so on.
From what I've found here:
Laravel matches routes from the top down. So all you need to do is put 'campaigns/add' above the wildcard route.
And that's what I've done:
routes.php
Route::group([
'prefix' => Localization::setLocale(),
'middleware' => ['localeSessionRedirect', 'localizationRedirect']
// LaravelLocalization (https://github.com/mcamara/laravel-localization)
], function() {
Route::auth();
// admin routes
Route::group([
'prefix' => env('ADMIN_PREFIX', 'admin'),
'as' => env('ADMIN_PREFIX', 'admin') . '::',
'middleware' => ['auth']
], function() {
/*
* ADMIN ROUTES
*/
});
Route::get('/{page}', [
'as' => 'page',
'uses' => 'Website\WebsiteController#showPage'
])->where(['page' => '.+(\.html)']);
});
But when I try to call an admin route, Laravel throws this error:
Missing argument 1 for App\Http\Controllers\Website\Core\WebsiteCoreController::showPage()
So I suppose I'm doing something wrong... Any suggestions on how to fix my code?
Thanks everyone in advance
I have these three Routes
Route::get('login', [
'uses' => 'loginController#showLogin',
'as' => 'login.show',
'before' => 'guest'
]);
Route::get('dashboard', [
'uses' => 'DashboardController#index',
'as' => 'dashboard.show'
]);
Route::filter('guest', function()
{
if (Auth::check())
return Redirect::route('dashboard.show');
});
When I log-in the Auth:check() recognize it, but instead of redirecting me to localhost:8000/dashboard it redirects me only to localhost:8000
Am'I doing something wrong?
Thank you very much for any suggestions.
Redirect::route() will only redirect to saved routes. You have named your first route 'login.show'. Your route 'dashboard' is actually named 'dashboard.show'. You will need to do Redirect::route('dashboard.show')
If you are just wanting to redirect to a URL then do Redirect::to('dashboard')