Laravel routing groups - laravel

I have a question about routing groups. I have two types of users and I can not use the role system. Following the laracast email verification video I was able to get a new type of user to work. So I can login and register no problem. However when I have both types of users routes going it starts rejecting logins and such.
I even tried separating the admin user routes and putting the artist user routes on a different php document but still will not allow two types of logins or to view the proper dashboard.
I have tried using namespace inside the group, prefix, and tried middleware to no avail.
Here's the routing code.
Route::group(['middleware' => ['web']], function () {
Route::get('/', function () {
return view('welcome');
});
Route::get('/artist', function () {
return view('artist');
});
Route::get('/sponsor', function () {
return view('sponsor');
});
Route::get('/viewer', function () {
return view('viewer');
});
Route::get('/contact', function () {
return view('contact');
});
// This is for the Artist Linkings
//Route::group(['middleware' => 'artist'], function () {
//Route::auth('artist');
//Route::get('art/dashboard', 'SessionsController#index');
//Route::get('art/dashboard', ['middleware' => 'artist', function() {
//return view('art/dashboard');
//}]);
//});
//Route::get('art/register', 'RegistrationController#register');
//Route::post('art/register', 'RegistrationController#postRegister');
//Route::get('register/confirm/{token}', 'RegistrationController#confirmEmail');
//Route::get('art/login', 'SessionsController#login');
//Route::post('login', 'SessionsController#postLogin');
//Route::get('/logout', 'SessionsController#logout');
//Route::get('art/dashboard', 'SessionsController#index');
//});
// Need to add the password stuff ect
// Route::group(['prefix' => 'viewer', 'namespace' => 'Viewer'], function () {
// require app_path('Http/Routes/viewers.php');
// });
// This is for all the Viewer Linkings
Route::get('viewer/register', 'ViewerRegistrationController#register');
Route::post('viewer/register', 'ViewerRegistrationController#postRegister');
Route::get('viewer/register/confirm/{token}', 'ViewerRegistrationController#confirmEmail');
Route::get('viewer/login', 'ViewerSessionsController#login');
Route::post('login', 'ViewerSessionsController#postLogin');
Route::get('/logout', 'ViewerSessionsController#logout');
Route::get('viewer/dashboard', 'ViewerSessionsController#index');
//});
//}]);

You can use this .
For artist user as you define
Route::group(["middleware" => ["auth.artist"], "prefix" => "artist","namespace"=>"Artist"], function() {
Route::controller('artist', 'UsersArtistController');
Route::controller('controles', 'controlsArtistController');
});
For viewer user if no any auth needed
Route::group("prefix" => "viewer","namespace"=>"Viewer"], function() {
Route::controller('Viewer ', 'UsersViewer Controller');
Route::controller('controles', 'controlsViewerController');
});

Route::group(['as'=>'admin.','prefix'=>'admin','namespace'=>'Admin','middleware'=>['auth','admin']], function (){
Route::get('dashboard','DashboardController#index')->name('dashboard');
Route::resource('tag','TagController');
Route::resource('category','CategoryController');
});
Route::group(['middleware'=>['auth']], function(){
Route::post('favorite/{post}/add','FavoriteController#add')->name('post.favorite');
Route::post('review/{id}/add','ReviewController#review')->name('review');
});
Route::group(['as'=>'user.','prefix'=>'user','namespace'=>'Author','middleware'=>['auth','user']], function (){
Route::get('dashboard','DashboardController#index')->name('dashboard');
Route::resource('post','PostController');
});

Related

Invalid route action when everything seems fine

My web.php is the one posted below. The problem with it is this part:
Route::group(['prefix' => 'agb-page'], function () {
Route::get('/view', ViewAgbPage::class)->name('agb_page_view');
Route::get('/add', AddAgbPage::class)->name('agb_page_add');
Route::get('/edit/{id}', EditAgbPage::class)->name('agb_page_edit');
});
For some reason it throws and error:
[2022-11-21 18:29:23] local.ERROR: Invalid route action: [App\Http\Livewire\Backend\Pages\Agb\ViewAgbPage]. {"exception":"[object] (UnexpectedValueException(code: 0): Invalid route action: [App\Http\Livewire\Backend\Pages\Agb\ViewAgbPage]. at /var/www/wdctue8/htdocs/active-security-Website/active-security/vendor/laravel/framework/src/Illuminate/Routing/RouteAction.php:92)
[stacktrace]
If I comment out this part, everything works fine. Don't understand what is the problem with it.
<?php
use App\Http\Controllers\UserLogoutController;
use App\Http\Livewire\Backend\Dashboard;
use App\Http\Livewire\Backend\Pages\Agb\AddAgbPage;
use App\Http\Livewire\Backend\Pages\Agb\EditAgbPage;
use App\Http\Livewire\Backend\Pages\Agb\ViewAgbPage;
use App\Http\Livewire\Backend\Pages\AllBanners\AddAllBanners;
use App\Http\Livewire\Backend\Pages\AllBanners\EditAllBanners;
use App\Http\Livewire\Backend\Pages\AllBanners\ViewAllBanners;
use App\Http\Livewire\Backend\Pages\Banner\AddHomeBanner;
use App\Http\Livewire\Backend\Pages\Banner\EditHomeBanner;
use App\Http\Livewire\Backend\Pages\Banner\HomeBanner;
use App\Http\Livewire\Backend\Pages\Company\AddSectionOne;
use App\Http\Livewire\Backend\Pages\Company\AddSectionTwo;
use App\Http\Livewire\Backend\Pages\Company\EditSectionOne;
use App\Http\Livewire\Backend\Pages\Company\EditSectionTwo;
use App\Http\Livewire\Backend\Pages\Company\ViewSectionOne;
use App\Http\Livewire\Backend\Pages\Company\ViewSectionTwo;
use App\Http\Livewire\Backend\Pages\Contacts\AddContactSection;
use App\Http\Livewire\Backend\Pages\Contacts\EditContactSection;
use App\Http\Livewire\Backend\Pages\Contacts\ViewContacts;
use App\Http\Livewire\Backend\Pages\Contacts\ViewContactSection;
use App\Http\Livewire\Backend\Pages\Footer\AddFooterAddress;
use App\Http\Livewire\Backend\Pages\Footer\EditFooterAddress;
use App\Http\Livewire\Backend\Pages\Footer\FooterAddress;
use App\Http\Livewire\Backend\Pages\Footer\Logos\EditFooterLogo;
use App\Http\Livewire\Backend\Pages\Footer\Logos\ViewFooterLogo;
use App\Http\Livewire\Backend\Pages\Footer\Privacy\AddPrivacySettings;
use App\Http\Livewire\Backend\Pages\Footer\Privacy\EditPrivacySettings;
use App\Http\Livewire\Backend\Pages\Footer\Privacy\Tabs\AddPrivacySettingsTab;
use App\Http\Livewire\Backend\Pages\Footer\Privacy\Tabs\EditPrivacySettingsTab;
use App\Http\Livewire\Backend\Pages\Footer\Privacy\Tabs\ViewPrivacySettingsTab;
use App\Http\Livewire\Backend\Pages\Footer\Privacy\ViewPrivacySettings;
use App\Http\Livewire\Backend\Pages\Footer\Social\AddSocialCategory;
use App\Http\Livewire\Backend\Pages\Footer\Social\AddSocialMedia;
use App\Http\Livewire\Backend\Pages\Footer\Social\EditSocialCategory;
use App\Http\Livewire\Backend\Pages\Footer\Social\EditSocialMedia;
use App\Http\Livewire\Backend\Pages\Footer\Social\ViewSocialCategory;
use App\Http\Livewire\Backend\Pages\Footer\Social\ViewSocialMedia;
use App\Http\Livewire\Backend\Pages\Home\Clients\AddHomeClients;
use App\Http\Livewire\Backend\Pages\Home\Clients\EditHomeClients;
use App\Http\Livewire\Backend\Pages\Home\Clients\ViewHomeClients;
use App\Http\Livewire\Backend\Pages\Home\Sections\AddHomeSection1;
use App\Http\Livewire\Backend\Pages\Home\Sections\AddHomeSection2;
use App\Http\Livewire\Backend\Pages\Home\Sections\AddHomeSection5;
use App\Http\Livewire\Backend\Pages\Home\Sections\EditHomeSection1;
use App\Http\Livewire\Backend\Pages\Home\Sections\EditHomeSection2;
use App\Http\Livewire\Backend\Pages\Home\Sections\EditHomeSection5;
use App\Http\Livewire\Backend\Pages\Home\Sections\ViewHomeSection1;
use App\Http\Livewire\Backend\Pages\Home\Sections\ViewHomeSection2;
use App\Http\Livewire\Backend\Pages\Home\Sections\ViewHomeSection5;
use App\Http\Livewire\Backend\Pages\Home\Slider\AddHomeSliders;
use App\Http\Livewire\Backend\Pages\Home\Slider\EditHomeSliders;
use App\Http\Livewire\Backend\Pages\Home\Slider\ViewHomeSliders;
use App\Http\Livewire\Backend\Pages\Job\AddJobSection;
use App\Http\Livewire\Backend\Pages\Job\EditJobSection;
use App\Http\Livewire\Backend\Pages\Job\ViewJobSection;
use App\Http\Livewire\Backend\Pages\Privacy\AddFooterPrivacy;
use App\Http\Livewire\Backend\Pages\Privacy\EditFooterPrivacy;
use App\Http\Livewire\Backend\Pages\Privacy\ViewFooterPrivacy;
use App\Http\Livewire\Backend\Pages\Services\AddServices;
use App\Http\Livewire\Backend\Pages\Services\Banner\EditBanners;
use App\Http\Livewire\Backend\Pages\Services\Banner\ViewBanners;
use App\Http\Livewire\Backend\Pages\Services\EditServices;
use App\Http\Livewire\Backend\Pages\Services\Section\AddLastSection;
use App\Http\Livewire\Backend\Pages\Services\Section\EditLastSection;
use App\Http\Livewire\Backend\Pages\Services\Section\ViewLastSection;
use App\Http\Livewire\Backend\Pages\Services\ViewServices;
use App\Http\Livewire\Frontend\Agb;
use App\Http\Livewire\Frontend\BaustellenbewacHung;
use App\Http\Livewire\Frontend\Centerbewachung;
use App\Http\Livewire\Frontend\Contact;
use App\Http\Livewire\Frontend\Datenschutz;
use App\Http\Livewire\Frontend\Empfangsdienst;
use App\Http\Livewire\Frontend\HomePage;
use App\Http\Livewire\Frontend\Impressum;
use App\Http\Livewire\Frontend\Jobs;
use App\Http\Livewire\Frontend\Kaufhausdetektive;
use App\Http\Livewire\Frontend\ObjektUndWerkschutz;
use App\Http\Livewire\Frontend\OpeningAndClosingService;
use App\Http\Livewire\Frontend\RevierFahrten;
use App\Http\Livewire\Frontend\ShopGuard;
use App\Http\Livewire\Frontend\Unternehmen;
use App\Http\Livewire\Frontend\VeranstaltungsSchutz;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
*/
// Route::get('/', function () {
// return view('welcome');
// });
//================ start Frontend routes ================
// homepage
Route::get('Userlogout', [UserLogoutController::class, 'user_logout'])->name('user.logout');
Route::get('/', HomePage::class)->name('homePage');
// ObjektPage
Route::get('/objekt-und-werkschutz', ObjektUndWerkschutz::class)->name('ObjektPage');
// Centerbewachung
Route::get('/centerbewachung', Centerbewachung::class)->name('CenterbewachungPage');
// Kaufhausdetektive
Route::get('/kaufhausdetektive', Kaufhausdetektive::class)->name('KaufhausdetektivePage');
// BaustellenbewacHung
Route::get('/baustellenbewachung', BaustellenbewacHung::class)->name('baustellenbewachungPage');
// OpeningAndClosingService
Route::get('/opening-and-closing-service', OpeningAndClosingService::class)->name('openingAndclosingPage');
// RevierFahrten
Route::get('/revierfahrten', RevierFahrten::class)->name('revierfahrtenPage');
// Empfangsdienst
Route::get('/empfangsdienst', Empfangsdienst::class)->name('empfangsdienst');
// ShopGuard
Route::get('/shop-guard', ShopGuard::class)->name('ShopGuardPage');
// VeranstaltungsSchutz
Route::get('/veranstaltungsschutz', VeranstaltungsSchutz::class)->name('VeranstaltungsSchutzPage');
// Unternehmen
Route::get('/unternehmen', Unternehmen::class)->name('UnternehmenPage');
// Jobs
Route::get('/jobs', Jobs::class)->name('JobsPage');
// Contact
Route::get('/Kontakt', Contact::class)->name('ContactPage');
// Impressum
Route::get('/impressum', Impressum::class)->name('ImpressumPage');
// Datenschutz
Route::get('/datenschutz', Datenschutz::class)->name('DatenschutzPage');
// Agb
Route::get('/agb', Agb::class)->name('AgbPage');
//================ end Frontend routes ================
//================ start Admin routes ================
Route::middleware([
'auth:sanctum',
config('jetstream.auth_session'),
'verified'
])->group(function () {
// Route::get('/dashboard', function () {
// return view('dashboard');
// })->name('dashboard');
Route::group(['middleware' => ['adminlogin']], function () {
Route::get('/dashboard', Dashboard::class)->name('dashboard');
// Manage home page
Route::group(['prefix' => 'mange-banner'], function () {
Route::get('/view-banner', HomeBanner::class)->name('viewHomebanner');
Route::get('/add-banner', AddHomeBanner::class)->name('addHomebanner');
Route::get('/edit-banner/{id}', EditHomeBanner::class)->name('editHomebanner');
});
// Manage other pages banner
Route::group(['prefix' => 'mange-All-banner'], function () {
Route::get('/view', ViewAllBanners::class)->name('view_all_banner');
Route::get('/add', AddAllBanners::class)->name('add_all_banners');
Route::get('/edit/{id}', EditAllBanners::class)->name('edit_all_banner');
});
//============== home page Section1 ==============
Route::group(['prefix' => 'manage-home'], function () {
// Home Section1
Route::get('/view-section/one', ViewHomeSection1::class)->name('manageHomeSection1');
Route::get('/add-section/one', AddHomeSection1::class)->name('addHomesection1');
Route::get('/edit-section/one/{id}', EditHomeSection1::class)->name('editHomesection1');
// Home Section2
Route::get('/view-section/two', ViewHomeSection2::class)->name('viewHomeSection2');
Route::get('/add-section/two', AddHomeSection2::class)->name('add_HomeSection2');
Route::get('/edit-section/two/{id}', EditHomeSection2::class)->name('edit_HomeSection2');
// View Home Clients
Route::get('/view-client/logo', ViewHomeClients::class)->name('viewHomeclients');
Route::get('/add-client/logo', AddHomeClients::class)->name('addHomeclients');
Route::get('/edit-client/logo/{id}', EditHomeClients::class)->name('editHomeclients');
// View Home Sliders
Route::get('/view-home/slider', ViewHomeSliders::class)->name('viewHomesliders');
Route::get('/add-home/slider', AddHomeSliders::class)->name('addHomesliders');
Route::get('/edit-home/slider/{id}', EditHomeSliders::class)->name('editHomesliders');
// ViewHomeSection5
Route::get('/view-home/section/five', ViewHomeSection5::class)->name('ViewHomeSection5');
Route::get('/add-home/section/five', AddHomeSection5::class)->name('Add_Home_Section5');
Route::get('/edit-home/section/five/{id}', EditHomeSection5::class)->name('edit_Home_Section5');
});
Route::group(['prefix' => 'manage-footer'], function () {
// FooterAddress
Route::get('/contact-view', FooterAddress::class)->name('footer_address');
Route::get('/contact-add', AddFooterAddress::class)->name('Add_footer_address');
Route::get('/contact-edit/{id}', EditFooterAddress::class)->name('edit_footer_address');
Route::group(['prefix' => 'social'], function () {
// ViewSocialMedia
Route::get('/view', ViewSocialMedia::class)->name('view_social_media');
Route::get('/add', AddSocialMedia::class)->name('add_social_media');
Route::get('/edit/{id}', EditSocialMedia::class)->name('edit_social_media');
Route::get('/view-category', ViewSocialCategory::class)->name('view_socialMediaCat');
Route::get('/add-category', AddSocialCategory::class)->name('Add_socialMediaCat');
Route::get('/edit-category/{id}', EditSocialCategory::class)->name('edit_socialMediaCat');
});
// ViewFooterLogo
Route::group(['prefix' => 'logos'], function () {
Route::get('/view', ViewFooterLogo::class)->name('view_footer_logos');
Route::get('/edit/{id}', EditFooterLogo::class)->name('edit_footer_logos');
});
//
Route::group(['prefix' => 'privacy'], function () {
Route::get('/view', ViewPrivacySettings::class)->name('view_privacy_settings');
Route::get('/add', AddPrivacySettings::class)->name('add_privacy_settings');
Route::get('/edit/{id}', EditPrivacySettings::class)->name('edit_privacy_settings');
});
Route::get('/view-tab', ViewPrivacySettingsTab::class)->name('view_privacy_Tabs');
Route::get('/add-tab', AddPrivacySettingsTab::class)->name('add_privacy_Tabs');
Route::get('/edit-tab/{id}', EditPrivacySettingsTab::class)->name('edit_privacy_Tabs');
Route::get('/page-view', ViewFooterPrivacy::class)->name('footer_Privacy_pageView');
Route::get('/page-add', AddFooterPrivacy::class)->name('addfooter_Privacytext');
Route::get('/page-edit/{id}', EditFooterPrivacy::class)->name('editfooter_Privacytext');
});
Route::group(['prefix' => 'agb-page'], function () {
Route::get('/view', ViewAgbPage::class)->name('agb_page_view');
Route::get('/add', AddAgbPage::class)->name('agb_page_add');
Route::get('/edit/{id}', EditAgbPage::class)->name('agb_page_edit');
});
Route::group(['prefix' => 'services'], function () {
Route::get('/view', ViewServices::class)->name('view_services');
Route::get('/add', AddServices::class)->name('add_services');
Route::get('/edit/{id}', EditServices::class)->name('edit_services');
Route::group(['prefix' => 'banner'], function () {
Route::get('/view', ViewBanners::class)->name('view_services_banner');
Route::get('/edit/{id}', EditBanners::class)->name('edit_services_banner');
});
Route::group(['prefix' => 'section'], function () {
Route::get('/view', ViewLastSection::class)->name('view_last_section');
Route::get('/add', AddLastSection::class)->name('add_last_footer_section');
Route::get('/edit/{id}', EditLastSection::class)->name('edit_last_section');
});
});
// home section end
Route::group(['prefix' => 'Company'], function () {
Route::get('/sections/view', ViewSectionOne::class)->name('view_company_sections');
Route::get('/sections/add', AddSectionOne::class)->name('add_company_section1');
Route::get('/sections/edit/{id}', EditSectionOne::class)->name('edit_company_section1');
// ViewSectionTwo
Route::get('/section2/view', ViewSectionTwo::class)->name('viewCompanySections2');
Route::get('/section2/add', AddSectionTwo::class)->name('addCompanySections2');
Route::get('/section2/edit/{id}', EditSectionTwo::class)->name('editCompanySections2');
});
Route::group(['prefix' => 'job-section'], function () {
Route::get('/view', ViewJobSection::class)->name('view_job_section');
Route::get('/edit/{id}', EditJobSection::class)->name('edit_job_section');
Route::get('/add', AddJobSection::class)->name('add_last_section');
});
Route::group(['prefix' => 'Contacts'], function () {
Route::get('/view', ViewContacts::class)->name('view_Contacts');
Route::get('/view-section', ViewContactSection::class)->name('Manage_Contacts_section');
Route::get('/add-section', AddContactSection::class)->name('Add_Contacts_section');
Route::get('/edit-section/{id}', EditContactSection::class)->name('edit_Contacts_section');
});
// middle ware end
});
// middle ware end
// Manage home page
});
//================ end admin routes ================

Get route is not working in laravel when i hit get route using api its return nothing

when I hit get route it returns this.I tried to get routes by using this API laravel
Route::group(['prefix' => 'admin', 'middleware' => ['auth:admins']], function() {
// Route::group(['prefix' => 'admin'], function() {
Route::post('details', [PassportAuthController::class, 'details']);
// get all list of
Route::apiResource('/admins', AdminController::class);
// opening hours
Route::apiResource('openinghours', OpeningHourController::class);
// orders
Route::apiResource('admin-orders', AdminOrderController::class);
// Categories
Route::apiResource('admin-categories', AdminCategoryController::class);
Route::post('add-push-token', [PushTokenAdminController::class, 'store']);
// sizegroups
Route::apiResource('size-groups', AdminSizeGroupController::class);
// sizegroups
Route::apiResource('size-groups.size', SizeController::class);
// products
Route::apiResource('admin-products', AdminProductController::class);
// accessories
Route::apiResource('admin-accessory', AdminAccessoryController::class);
Route::post('product-accessory-update', [AdminAccessoryController::class, 'productAccessoryUpdate']);
// products accessories
Route::apiResource('admin-product-accessory', AdminProductAccessoryController::class);
// Route::get('me', [AdminController::class, 'admin']);
Route::get('me', [PassportAuthController::class, 'details']);
Route::post('category-image-upload', [AdminCategoryController::class, 'uploadImage'])->name('category.image.upload.post');
Route::post('category-image-delete', [AdminCategoryController::class, 'deleteImage'])->name('category.image.delete');
// Route::post('product-image-upload', [AdminProductController::class, 'uploadImage'])->name('product.image.upload.post');
Route::post('product-image-delete', [AdminProductController::class, 'deleteImage'])->name('product.image.delete');
// sending push notifciatin sued for testing
Route::post('sendPushNotification', [PushNotificationController::class, 'send']);
});
You define post mathod and postman call get method.
use match and any method you can access post and get method
Route::match(['get', 'post'], '/', function () {
//
});
Route::any('/', function () {
//
});

How to create a Route in Laravel to this scenario?

The basic idea is to work like a sub-domain architecture, but the user account will come after website's name.
I have a web service that is called myService.com.
I will have users like Paul, Anne, Jhon.
I want Laravel to be able to create home pages for Paul, Anne and Jhon like this:
myService.com/Paul = > Should redirects to Paul home page
myService.com/Anne = > Should redirects to Anne home page
myService.com/Jhon = > Should redirects to Jhon home page
but myService.com has its own home page and others pages too. I do like this:
Route::get('/', function () {
return view('home');//myService.com HOME page
});
Route::group(['prefix'=>'videos'], function (){
Route::get('/', function () {
return "all videos";
});
Route::get('/{id}', function ($id) {
return "Video => $id";
});
});
Route::group(['prefix'=>'articles'], function (){
Route::get('/', function () {
return "all articles";
});
Route::get('/{id}', function ($id) {
return "Article => $id";
});
});
For the users I will have almost the same URL structure:
myService.com/Paul
myService.com/Paul/videos
myService.com/Paul/videos/id
myService.com/Paul/articles
myService.com/Paul/articles/id
myService.com/Paul2
myService.com/Paul2/videos
myService.com/Paul2/videos/id
myService.com/Paul2/articles
myService.com/Paul2/articles/id
Since I will have unlimited users account I dont know how to design the Route structure for this scenario.
Is It should be like this?
Route::group(['prefix'=>'account'], function (){
Route::get('/', function ($account) {
return "user $account home page";//Ex myService.com/Paul
});
Route::group(['prefix'=>'videos'], function (){
Route::get('/', function () {
return "user account - all videos";//Ex myService.com/Paul/videos
});
Route::get('/{id}', function ($id) {
return "user account video => $id";//Ex myService.com/Paul/videos/id
});
});
Route::group(['prefix'=>'articles'], function (){
Route::get('/', function () {
return "user account - all articles";//Ex myService.com/Paul/articles
});
Route::get('/{id}', function ($id) {
return "user account articles => $id";//Ex myService.com/Paul/articles/id
});
});
});
This is what I did so far, but I dont know if it is a good approach. It is correct?
Define that group at the end of your routes so the other routes will have precedence. Then you can use slug for username (or whatever you are using)
Route::group(['prefix' => '{username}'], function(){
Route::group(['prefix' => 'videos'], function(){
...
});
});
But this groupe is more likely to try and pick up all your 404. Maybe you can add extra constraint
Route::group(['prefix' => '{username}'], function(){
...
})->where('username', '[A-Za-z]+');

Redirect entire route group to another url?

Given a route group like Route::group(['prefix' => 'foo',]) how would I redirect all routes under this group to domain.com?
I've tried:
Route::group(['prefix' => 'foo'], function() {
Route::get('/', function () {
return Redirect::to('http://domain.com');
});
});
But that would only redirect myoldsite.com/foo to domain.com, anything such as myoldsite.com/foo/deeper/path would just be a 404. Is there a way to catch all sub routes and redirect them?
You can add a catch-all parameter.
Route::group(['prefix' => 'foo'], function() {
Route::get('/{atsl}', function ($atsl) {
return Redirect::to('http://domain.com');
});
});

how to use the laravel subdomain routing function

I am using the following code its from the laravel 4 site
Route::group(array('domain' => '{account}.myapp.com'), function() {
Route::get('user/{id}', function($account, $id) {
// ...
return Redirect::to('https://www.myapp.com'.'/'.$account);
});
});
the idea is to redirect subdomain.myapp.com to myapp.com/user/subdomain
.what I have is not working any suggestions?sorry I just started with laravel about a month now.
Remove user/{id} and replace it with / and then use the following url https://accountname.myapp.com and it will redirect to https://www.myapp.com/accountname
Route::group(array('domain' => '{account}.myapp.com'), function() {
Route::get('/', function($account, $id) {
// ...
return Redirect::to('https://www.myapp.com'.'/'.$account);
});
});
Edit the answer to the correct answer
Route::group(array('domain' => '{account}.myapp.com'), function() {
Route::get('/', function($account) {
// ...
return Redirect::to('https://www.myapp.com/'.$account);
});
});
as Marc vd M answer but remove $id from get's closure function.
why use 'https://www.myapp.com'.'/'.$account and not 'https://www.myapp.com/'.$account

Resources