How to use laravel voyager with a second parameter? - php

I'm building an admin panel for an e-commerce app using the laravel voyager package. I made localization functionality in my app but it broke the sitename/admin link which goes to the voyager admin panel.
Every route takes a {lang} prefix so the correct URL for the admin panel should be sitename/en/admin. but upon going to the URL it gives me this error: Missing required parameter for [Route: voyager.login] [URI: {lang}/admin/login] [Missing parameter: lang].
Where should I pass my {lang} parameter so that the voyager package starts working?
this is my routes/web.php:
Route::group(['prefix' => '{lang}'], function () {
Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
});
});
this is voyager routes in vendor\tcg\voyager\routes\voyager.php:
<?PHP
use Illuminate\Support\Str;
use TCG\Voyager\Events\Routing;
use TCG\Voyager\Facades\Voyager;
use TCG\Voyager\Events\RoutingAdmin;
use TCG\Voyager\Events\RoutingAfter;
use Illuminate\Support\Facades\Route;
use TCG\Voyager\Events\RoutingAdminAfter;
/*
|--------------------------------------------------------------------------
| Voyager Routes
|--------------------------------------------------------------------------
|
| This file is where you may override any of the routes that are included
| with Voyager.
|
*/
Route::group(['as' => 'voyager.'], function () {
event(new Routing());
$namespacePrefix = '\\' . config('voyager.controllers.namespace') . '\\';
Route::get('login', ['uses' => $namespacePrefix . 'VoyagerAuthController#login', 'as' => 'login']);
Route::post('login', ['uses' => $namespacePrefix . 'VoyagerAuthController#postLogin', 'as' => 'postlogin']);
Route::group(['middleware' => 'admin.user'], function () use ($namespacePrefix) {
event(new RoutingAdmin());
// Main Admin and Logout Route
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerController#index', 'as' => 'dashboard']);
Route::post('logout', ['uses' => $namespacePrefix . 'VoyagerController#logout', 'as' => 'logout']);
Route::post('upload', ['uses' => $namespacePrefix . 'VoyagerController#upload', 'as' => 'upload']);
Route::get('profile', ['uses' => $namespacePrefix . 'VoyagerUserController#profile', 'as' => 'profile']);
try {
foreach (Voyager::model('DataType')::all() as $dataType) {
$breadController = $dataType->controller
? Str::start($dataType->controller, '\\')
: $namespacePrefix . 'VoyagerBaseController';
Route::get($dataType->slug . '/order', $breadController . '#order')->name($dataType->slug . '.order');
Route::post($dataType->slug . '/action', $breadController . '#action')->name($dataType->slug . '.action');
Route::post($dataType->slug . '/order', $breadController . '#update_order')->name($dataType->slug . '.update_order');
Route::get($dataType->slug . '/{id}/restore', $breadController . '#restore')->name($dataType->slug . '.restore');
Route::get($dataType->slug . '/relation', $breadController . '#relation')->name($dataType->slug . '.relation');
Route::post($dataType->slug . '/remove', $breadController . '#remove_media')->name($dataType->slug . '.media.remove');
Route::resource($dataType->slug, $breadController, ['parameters' => [$dataType->slug => 'id']]);
}
} catch (\InvalidArgumentException $e) {
throw new \InvalidArgumentException("Custom routes hasn't been configured because: " . $e->getMessage(), 1);
} catch (\Exception $e) {
// do nothing, might just be because table not yet migrated.
}
// Menu Routes
Route::group([
'as' => 'menus.',
'prefix' => 'menus/{menu}',
], function () use ($namespacePrefix) {
Route::get('builder', ['uses' => $namespacePrefix . 'VoyagerMenuController#builder', 'as' => 'builder']);
Route::post('order', ['uses' => $namespacePrefix . 'VoyagerMenuController#order_item', 'as' => 'order_item']);
Route::group([
'as' => 'item.',
'prefix' => 'item',
], function () use ($namespacePrefix) {
Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerMenuController#delete_menu', 'as' => 'destroy']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerMenuController#add_item', 'as' => 'add']);
Route::put('/', ['uses' => $namespacePrefix . 'VoyagerMenuController#update_item', 'as' => 'update']);
});
});
// Settings
Route::group([
'as' => 'settings.',
'prefix' => 'settings',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController#index', 'as' => 'index']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController#store', 'as' => 'store']);
Route::put('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController#update', 'as' => 'update']);
Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerSettingsController#delete', 'as' => 'delete']);
Route::get('{id}/move_up', ['uses' => $namespacePrefix . 'VoyagerSettingsController#move_up', 'as' => 'move_up']);
Route::get('{id}/move_down', ['uses' => $namespacePrefix . 'VoyagerSettingsController#move_down', 'as' => 'move_down']);
Route::put('{id}/delete_value', ['uses' => $namespacePrefix . 'VoyagerSettingsController#delete_value', 'as' => 'delete_value']);
});
// Admin Media
Route::group([
'as' => 'media.',
'prefix' => 'media',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerMediaController#index', 'as' => 'index']);
Route::post('files', ['uses' => $namespacePrefix . 'VoyagerMediaController#files', 'as' => 'files']);
Route::post('new_folder', ['uses' => $namespacePrefix . 'VoyagerMediaController#new_folder', 'as' => 'new_folder']);
Route::post('delete_file_folder', ['uses' => $namespacePrefix . 'VoyagerMediaController#delete', 'as' => 'delete']);
Route::post('move_file', ['uses' => $namespacePrefix . 'VoyagerMediaController#move', 'as' => 'move']);
Route::post('rename_file', ['uses' => $namespacePrefix . 'VoyagerMediaController#rename', 'as' => 'rename']);
Route::post('upload', ['uses' => $namespacePrefix . 'VoyagerMediaController#upload', 'as' => 'upload']);
Route::post('crop', ['uses' => $namespacePrefix . 'VoyagerMediaController#crop', 'as' => 'crop']);
});
// BREAD Routes
Route::group([
'as' => 'bread.',
'prefix' => 'bread',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerBreadController#index', 'as' => 'index']);
Route::get('{table}/create', ['uses' => $namespacePrefix . 'VoyagerBreadController#create', 'as' => 'create']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerBreadController#store', 'as' => 'store']);
Route::get('{table}/edit', ['uses' => $namespacePrefix . 'VoyagerBreadController#edit', 'as' => 'edit']);
Route::put('{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController#update', 'as' => 'update']);
Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController#destroy', 'as' => 'delete']);
Route::post('relationship', ['uses' => $namespacePrefix . 'VoyagerBreadController#addRelationship', 'as' => 'relationship']);
Route::get('delete_relationship/{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController#deleteRelationship', 'as' => 'delete_relationship']);
});
// Database Routes
Route::resource('database', $namespacePrefix . 'VoyagerDatabaseController');
// Compass Routes
Route::group([
'as' => 'compass.',
'prefix' => 'compass',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerCompassController#index', 'as' => 'index']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerCompassController#index', 'as' => 'post']);
});
event(new RoutingAdminAfter());
});
//Asset Routes
Route::get('voyager-assets', ['uses' => $namespacePrefix . 'VoyagerController#assets', 'as' => 'voyager_assets']);
event(new RoutingAfter());
});

Related

Problem with defining extra routes in voyager

I'm using the voyager package in my laravel app. I made a route group with a {lang} prefix for localization. everything is working fine in the base app but when I go to /admin which is the route for the voyager panel, it returns an error saying that I have a missing parameter.
in my own app's routes I simply do this:
Route::group(['prefix' => '{lang}'], function () {
//code...
});
However, the routes file for voyager is fairly complicated with several nested groups. I tried adding the prefix in many different lines but didn't get any results. I'd really appreciated if somebody could tell me where and how to add my {lang} prefix in this route file.
This is the routes file for voyager in vendor\tcg\voyager\routes\voyager.php:
<?PHP
use Illuminate\Support\Str;
use TCG\Voyager\Events\Routing;
use TCG\Voyager\Facades\Voyager;
use TCG\Voyager\Events\RoutingAdmin;
use TCG\Voyager\Events\RoutingAfter;
use Illuminate\Support\Facades\Route;
use TCG\Voyager\Events\RoutingAdminAfter;
/*
|--------------------------------------------------------------------------
| Voyager Routes
|--------------------------------------------------------------------------
|
| This file is where you may override any of the routes that are included
| with Voyager.
|
*/
Route::group(['as' => 'voyager.'], function () {
event(new Routing());
$namespacePrefix = '\\' . config('voyager.controllers.namespace') . '\\';
Route::get('login', ['uses' => $namespacePrefix . 'VoyagerAuthController#login', 'as' => 'login']);
Route::post('login', ['uses' => $namespacePrefix . 'VoyagerAuthController#postLogin', 'as' => 'postlogin']);
Route::group(['middleware' => 'admin.user'], function () use ($namespacePrefix) {
event(new RoutingAdmin());
// Main Admin and Logout Route
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerController#index', 'as' => 'dashboard']);
Route::post('logout', ['uses' => $namespacePrefix . 'VoyagerController#logout', 'as' => 'logout']);
Route::post('upload', ['uses' => $namespacePrefix . 'VoyagerController#upload', 'as' => 'upload']);
Route::get('profile', ['uses' => $namespacePrefix . 'VoyagerUserController#profile', 'as' => 'profile']);
try {
foreach (Voyager::model('DataType')::all() as $dataType) {
$breadController = $dataType->controller
? Str::start($dataType->controller, '\\')
: $namespacePrefix . 'VoyagerBaseController';
Route::get($dataType->slug . '/order', $breadController . '#order')->name($dataType->slug . '.order');
Route::post($dataType->slug . '/action', $breadController . '#action')->name($dataType->slug . '.action');
Route::post($dataType->slug . '/order', $breadController . '#update_order')->name($dataType->slug . '.update_order');
Route::get($dataType->slug . '/{id}/restore', $breadController . '#restore')->name($dataType->slug . '.restore');
Route::get($dataType->slug . '/relation', $breadController . '#relation')->name($dataType->slug . '.relation');
Route::post($dataType->slug . '/remove', $breadController . '#remove_media')->name($dataType->slug . '.media.remove');
Route::resource($dataType->slug, $breadController, ['parameters' => [$dataType->slug => 'id']]);
}
} catch (\InvalidArgumentException $e) {
throw new \InvalidArgumentException("Custom routes hasn't been configured because: " . $e->getMessage(), 1);
} catch (\Exception $e) {
// do nothing, might just be because table not yet migrated.
}
// Menu Routes
Route::group([
'as' => 'menus.',
'prefix' => 'menus/{menu}',
], function () use ($namespacePrefix) {
Route::get('builder', ['uses' => $namespacePrefix . 'VoyagerMenuController#builder', 'as' => 'builder']);
Route::post('order', ['uses' => $namespacePrefix . 'VoyagerMenuController#order_item', 'as' => 'order_item']);
Route::group([
'as' => 'item.',
'prefix' => 'item',
], function () use ($namespacePrefix) {
Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerMenuController#delete_menu', 'as' => 'destroy']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerMenuController#add_item', 'as' => 'add']);
Route::put('/', ['uses' => $namespacePrefix . 'VoyagerMenuController#update_item', 'as' => 'update']);
});
});
// Settings
Route::group([
'as' => 'settings.',
'prefix' => 'settings',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController#index', 'as' => 'index']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController#store', 'as' => 'store']);
Route::put('/', ['uses' => $namespacePrefix . 'VoyagerSettingsController#update', 'as' => 'update']);
Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerSettingsController#delete', 'as' => 'delete']);
Route::get('{id}/move_up', ['uses' => $namespacePrefix . 'VoyagerSettingsController#move_up', 'as' => 'move_up']);
Route::get('{id}/move_down', ['uses' => $namespacePrefix . 'VoyagerSettingsController#move_down', 'as' => 'move_down']);
Route::put('{id}/delete_value', ['uses' => $namespacePrefix . 'VoyagerSettingsController#delete_value', 'as' => 'delete_value']);
});
// Admin Media
Route::group([
'as' => 'media.',
'prefix' => 'media',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerMediaController#index', 'as' => 'index']);
Route::post('files', ['uses' => $namespacePrefix . 'VoyagerMediaController#files', 'as' => 'files']);
Route::post('new_folder', ['uses' => $namespacePrefix . 'VoyagerMediaController#new_folder', 'as' => 'new_folder']);
Route::post('delete_file_folder', ['uses' => $namespacePrefix . 'VoyagerMediaController#delete', 'as' => 'delete']);
Route::post('move_file', ['uses' => $namespacePrefix . 'VoyagerMediaController#move', 'as' => 'move']);
Route::post('rename_file', ['uses' => $namespacePrefix . 'VoyagerMediaController#rename', 'as' => 'rename']);
Route::post('upload', ['uses' => $namespacePrefix . 'VoyagerMediaController#upload', 'as' => 'upload']);
Route::post('crop', ['uses' => $namespacePrefix . 'VoyagerMediaController#crop', 'as' => 'crop']);
});
// BREAD Routes
Route::group([
'as' => 'bread.',
'prefix' => 'bread',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerBreadController#index', 'as' => 'index']);
Route::get('{table}/create', ['uses' => $namespacePrefix . 'VoyagerBreadController#create', 'as' => 'create']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerBreadController#store', 'as' => 'store']);
Route::get('{table}/edit', ['uses' => $namespacePrefix . 'VoyagerBreadController#edit', 'as' => 'edit']);
Route::put('{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController#update', 'as' => 'update']);
Route::delete('{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController#destroy', 'as' => 'delete']);
Route::post('relationship', ['uses' => $namespacePrefix . 'VoyagerBreadController#addRelationship', 'as' => 'relationship']);
Route::get('delete_relationship/{id}', ['uses' => $namespacePrefix . 'VoyagerBreadController#deleteRelationship', 'as' => 'delete_relationship']);
});
// Database Routes
Route::resource('database', $namespacePrefix . 'VoyagerDatabaseController');
// Compass Routes
Route::group([
'as' => 'compass.',
'prefix' => 'compass',
], function () use ($namespacePrefix) {
Route::get('/', ['uses' => $namespacePrefix . 'VoyagerCompassController#index', 'as' => 'index']);
Route::post('/', ['uses' => $namespacePrefix . 'VoyagerCompassController#index', 'as' => 'post']);
});
event(new RoutingAdminAfter());
});
//Asset Routes
Route::get('voyager-assets', ['uses' => $namespacePrefix . 'VoyagerController#assets', 'as' => 'voyager_assets']);
event(new RoutingAfter());
});

Laravel Route Url - Query String - Multi Level

I am trying to achieve url structure like below.
example.com/clients/{client_id} //done
example.com/clients/{client_id}{project_id} // issues
Error is Missing required parameters for [Route: clients.show_project] [URI: clients/{client}/{project_id}].
Route::group(['prefix' => 'clients', 'as' => 'clients.'], function () {
Route::get('/', [
'uses' => 'ClientsController#index',
'as' => 'index',
]);
Route::get('/create', [
'uses' => 'ClientsController#create',
'as' => 'create',
]);
Route::post('/store', [
'uses' => 'ClientsController#store',
'as' => 'store',
]);
Route::group(['prefix' => '{client}', '__rp' => ['menu' => 'clients']], function () {
Route::get('/', [
'uses' => 'ClientsController#show_client',
'as' => 'show',
]);
});
Route::group(['prefix' => '{client}/{project_id}'], function () {
Route::get('/', [
'uses' => 'ClientsController#show_project',
'as' => 'show_project',
]);
});
});
On view
{{ $task->title }}
Controller
public function show_project($client, $project_id)
{
$project_threads = Project_Threads::where('project_id', $project_id)->get();
return $project_threads;
}
The problem is in your view. Your have to pass params in an array in route(). Try this:
{{ $task->title }}

Middleware auth not working with web Laravel 5.2

Hi I am having some problem with authentication in laravel. I have to use two middleware 1. is web and 2. auth . I am using web middleware so that I can use session to show flash messages. and want to use auth middleware to do authentication of users/admin. but I am facing some problems.
below is my function to check authorization and to redirect to their respective routes
public function postLoginForm(){
$email=Input::get('email');
$password=Input::get('password');
$data=[
'email'=>$email,
'password'=>$password
];
$rules=[
'email'=>'required',
'password'=>'required'
];
$validator=Validator::make($data,$rules);
if($validator->fails()){
Session::flash('fail', 'Oops Something went wrong!!');
return redirect()->back()->withErrors($validator);
}
else{
if(Auth::attempt($data)){
$checkStatus=User::select('*')->where('email',$email)->first();
Session::put('email',$checkStatus->email);
Session::put('user_type',$checkStatus->user_type);
if($checkStatus['user_type']=='4'){
if($checkStatus['status']=='0'){
Session::flash('wait', 'Registration is not approved!!');
return "student";
return redirect()->back();
}
else{
return "student else";
return Redirect::route('get.student.dashBoard');
}
}
else if($checkStatus['user_type']=='1'){
return Redirect::route('get.admin.dashBoard');
}
else if($checkStatus['user_type']=='2'){
return 'admin sir view';
return Redirect::route('get.admin.dashBoard');
}
else if($checkStatus['user_type']=='3'){
return 'admin other view';
return Redirect::route('get.admin.dashBoard');
}
else{
Session::flash('fail', 'Oops Something went wrong!!');
return redirect()->back();
}
}
else{
Session::flash('fail', 'Login details not matched!!');
return redirect()->back();
}
}
return 'nothing works';
}
below is my routes for admin
Route::group(['middleware' => ['web']], function () {
Route::get('/login',
['as' => 'get.login.page',
'uses' => 'LoginController#getLoginPage']);
Route::post('/login-done',
['as' => 'post.login.page',
'uses' => 'LoginController#postLoginForm']);
Route::get('/register',
['as' => 'get.register.page',
'uses' => 'LoginController#getRegisterPage']);
Route::post('/register',
['as' => 'post.register.form',
'uses' => 'LoginController#postRegisterForm']);
Route::get('/forgot-password',
['as' => 'get.forgotPassword.form',
'uses' => 'LoginController#getForgotPasswordForm']);
Route::group(['middleware' => ['auth']], function () {
Route::get('/admin-dashboard',
['as' => 'get.admin.dashBoard',
'uses' => 'admin\PageController#getAdminDashboard']);
Route::get('/all-achievements',
['as' => 'get.achievements',
'uses' => 'admin\AchievementsController#getAchievementsList']);
Route::get('/new-achievement',
['as' => 'get.add.achievement',
'uses' => 'admin\AchievementsController#getAddAchievement']);
Route::post('/add-achievement',
['as' => 'post.achievementsForm',
'uses' => 'admin\AchievementsController#postAchievements']);
Route::get('remove-achievement/{achie_slug}',
['as' => 'post.delete.achievements',
'uses' => 'admin\AchievementsController#postDeleteAchievement']);
Route::get('edit-achievement/{achie_slug}',
['as' => 'get.edit.achievements',
'uses' => 'admin\AchievementsController#getEditAchievement']);
Route::post('update-achievement/{ach_id}',
['as' => 'post.edited.achievement',
'uses' => 'admin\AchievementsController#postEditedAchievement']);
Route::get('/all-news',
['as' => 'get.news.list',
'uses' => 'admin\NewsController#getNewsList']);
Route::get('/add-news',
['as' => 'get.add.news',
'uses' => 'admin\NewsController#getAddNews']);
Route::post('/add-news',
['as' => 'post.add.news',
'uses' => 'admin\NewsController#postAddNews']);
Route::get('/delete-news/{news_slug}',
['as' => 'get.delete.news',
'uses' => 'admin\NewsController#postDeleteNews']);
Route::get('/edit-news/{news_slug}',
['as' => 'get.edit.news',
'uses' => 'admin\NewsController#getEditNews']);
Route::post('/edit-news/{news_slug}',
['as' => 'post.edited.news',
'uses' => 'admin\NewsController#postEditedNews']);
Route::get('/all-admins',
['as' => 'get.admin.list',
'uses' => 'admin\AdminController#getAllAdminList']);
Route::get('/add-admin',
['as' => 'add.new.admin',
'uses' => 'admin\AdminController#getAddNewAdmin']);
Route::post('/add-new-admin',
['as' => 'post.add.new.admin',
'uses' => 'admin\AdminController#postAddNewAdmin']);
Route::get('/all-schedule',
['as' => 'get.timeTable.list',
'uses' => 'admin\TimeTableController#getTimeTableList']);
Route::get('/add-schedule/{id}',
['as' => 'add.timeTable',
'uses' => 'admin\TimeTableController#getAddNewBatch']);
Route::post('/add-new-batch',
['as' => 'add.newBatch',
'uses' => 'admin\TimeTableController#postAddNewBatch']);
Route::post('/save-year-batch',
['as' => 'save.year.batch',
'uses' => 'admin\TimeTableController#postSaveYearBatch']);
Route::get('/schedule-table/{year}',
['as' => 'view.schedule.table',
'uses' => 'admin\TimeTableController#getScheduleTable']);
Route::get('/delete-schedule/{slug}',
['as' => 'delete.schedule.one',
'uses' => 'admin\TimeTableController#postDeleteOneSchedule']);
Route::get('/edit-schedule/{slug}',
['as' => 'edit.schedule.one',
'uses' => 'admin\TimeTableController#getEditScheduleForm']);
Route::post('/save-edited-schedule/{id}',
['as' => 'save.edited.schedule',
'uses' => 'admin\TimeTableController#postEditScheduleForm']);
Route::get('/all-results',
['as' => 'get.all.results',
'uses' => 'admin\ResultsController#getAllResults']);
Route::get('/add-result',
['as' => 'get.add.results',
'uses' => 'admin\ResultsController#getAddResult']);
Route::post('/add-new-result',
['as' => 'post.add.result',
'uses' => 'admin\ResultsController#postAddResult']);
Route::get('/delete-result/{id}',
['as' => 'get.delete.student.result',
'uses' => 'admin\ResultsController#getDeleteResult']);
Route::get('/edit-result/{id}',
['as' => 'get.edit.student.result',
'uses' => 'admin\ResultsController#getEditResult']);
Route::post('/save-edited-result/{id}',
['as' => 'post.edited.result',
'uses' => 'admin\ResultsController#postEditedResult']);
Route::get('/contact-messages',
['as' => 'get.contact.message',
'uses' => 'admin\ContactMessageController#getAllContactMessages']);
Route::get('/contact-messages/{id}',
['as' => 'get.delete.contact.message',
'uses' => 'admin\ContactMessageController#getDeleteContactMessages']);
});
});
every time i try to login it redirects me to the same login page. please guide me whats wrong with this.
You should remove web middleware from middleware group to make it work. It applies to all routes inside web.php (5.3) and routes.php (5.2.27 and higher) automatically and if you'll add it manually, it will break session related functionality.

Laravel authenticate login route

I am using laravel 5.1, after user logged in, the url for login and register still can be access by user.
My current implementation of the route as follow:
<?php
$s = 'public.';
Route::get('/', ['as' => $s . 'home', 'uses' => 'PagesController#getHome']);
$a = 'auth.';
Route::get('/login', [ 'as' => $a . 'login', 'uses' => 'Auth\AuthController#getLogin']);
Route::post('/login', ['as' => $a . 'login-post', 'uses' => 'Auth\AuthController#postLogin']);
Route::get('/register', ['as' => $a . 'register', 'uses' => 'Auth\AuthController#getRegister']);
Route::post('/register', ['as' => $a . 'register-post', 'uses' => 'Auth\AuthController#postRegister']);
Route::get('/password', ['as' => $a . 'password', 'uses' => 'Auth\PasswordResetController#getPasswordReset']);
Route::post('/password', ['as' => $a . 'password-post', 'uses' => 'Auth\PasswordResetController#postPasswordReset']);
Route::get('/password/{token}', ['as' => $a . 'reset', 'uses' => 'Auth\PasswordResetController#getPasswordResetForm']);
Route::post('/password/{token}',['as' => $a . 'reset-post', 'uses' => 'Auth\PasswordResetController#postPasswordResetForm']);
$s = 'social.';
Route::get('/social/redirect/{provider}', ['as' => $s . 'redirect', 'uses' => 'Auth\AuthController#getSocialRedirect']);
Route::get('/social/handle/{provider}', ['as' => $s . 'handle', 'uses' => 'Auth\AuthController#getSocialHandle']);
Route::group(['prefix' => 'admin', 'middleware' => 'auth:administrator'], function()
{
$a = 'admin.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'AdminController#getHome']);
});
Route::group(['prefix' => 'user', 'middleware' => 'auth:user'], function()
{
$a = 'user.';
Route::get('/', ['as' => $a . 'home', 'uses' => 'UserController#getHome']);
});
Route::group(['middleware' => 'auth:all'], function()
{
$a = 'authenticated.';
Route::get('/logout', ['as' => $a . 'logout', 'uses' => 'Auth\AuthController#getLogout']);
});
I tried the following method but it doesn't work out:
Route::get('/login', ['before'=> 'auth', 'as' => $a . 'login', 'uses' => 'Auth\AuthController#getLogin']);
Thanks!!
You need to implement a helper(Middleware) for the login to do the redirect. Check app/Http/Middleware/RedirectIfAuthenticated.php its a good example to start from. No need to create routes for this.

Laravel Route group issue

I have been using laravel for a while now, but I stumbled across an error which I have never encountered before. It is probably me overlooking it, but with the route file given below, the route group with the prefix account gives a blank page. When going to /account/anunregisteredroute it does give a httpnotfoundexception
My routes.php file:
http://pastebin.com/EnnGSm10
By adding a / before the parameter you can solve this issue:
Route::get('/{username}', ['as' => 'account-profile', 'uses' => 'AccountController#getProfile']);
This piece of code worked for me:
Route::group(['prefix' => 'account'], function () {
Route::get('/{username}', ['as' => 'account-profile', 'uses' => function($username){
echo $username;
}]);
Route::get('profile', ['as' => 'account-edit-profile', 'uses' => 'AccountController#getUpdate', 'before' => 'auth']);
Route::post('profile', ['as' => 'account-edit-profile', 'uses' => 'AccountController#postUpdate', 'before' => 'auth|csrf']);
Route::group(['before' => 'guest'], function () {
Route::get('create', ['as' => 'account-create', 'uses' => 'AccountController#getCreate']);
Route::get('signin', ['as' => 'account-signin', 'uses' => 'AccountController#getSignin']);
Route::group(['before' => 'csrf'], function() {
Route::post('create', ['as' => 'account-create', 'uses' => 'AccountController#postCreate']);
Route::post('signin', ['as' => 'account-signin', 'uses' => 'AccountController#postSignin']);
});
});
});
I got the expected output.

Categories