I'm using Laravel routing subdomains to handle all subdomains. It works fine for the subdomain, but when I customize the routes for the primary domain routes is overwritten I think it because the route names are fixed for both subdomain and main domain so what is the proper way to handle this issue?
This is what is in my routes file at present;
Route::domain('{company}.' . config('app.url'))->group(function () {
include "allRoutes.php";
});
Route::domain(config('app.url'))->group(function() {
include "allRoutes.php";
});
[enter image description here][1]
here is part of the content of the allRoutes.php file
[1]: https://i.stack.imgur.com/Bzm0F.png
From your question, it looks as though you're having trouble when referencing routes because they are using the same name.
You should provide a name for your domained routes which effectively namespaces the naming.
Route::domain('{company}.' . config('app.url'))->name('sub.')->group(function () {
Route::get('/', 'HomeController#index')->name('home');
});
Route::domain(config('app.url'))->name('main.')->group(function() {
Route::get('/', 'HomeController#index')->name('home');
});
Then later when referencing these you'll be able to use
route('sub.home', ['company']) for the subdomain route and
route('main.home') for the main domain
Related
So I just pulled my code to this linux server and after some testing realized the /admin route was somehow trying to load the main page, which is weird since on my test server (Windows) it's working well.
The structure of /public looks like this:,
/public
/site
/admin
With the assets for each part of the website inside it's folder.
Console shows a lot of errors related to JS and CSS paths like this:
http://myip/admin/site/js/popper.min.js which is curious because the proper path would be http://myip/admin/js/popper.min.js.
I tried to change the /admin route to change the route behavior to redirect but it looks like nothing has changed, the route seems to take no action.
Here's my routes file:
// Site
Route::get('/', 'SliderController#showSlider'); // Show Sliders
Route::redirect('/admin', '/login');
// AutenticaĆ§Ć£o
Auth::routes();
Route::group(['middleware' => 'auth'], function () {
// Admin
Route::get('/admin', 'HomeController#index')->name('admin');
// Sliders
Route::get('/sliders', 'SliderController#listSlider'); // List Sliders
Route::post('/sliders/new', 'SliderController#createSlider'); // New Slider
Route::get('/sliders/edit/{id}', ['as' => '/sliders/edit/', 'uses' => 'SliderController#editSlider']); // Edit Slider
// Slides
Route::post('/slides/create/', 'SlideController#createSlide'); // Create Slide
Route::post('/slides/update', 'SlideController#updateSlide'); // Update Slide
Route::post('/slides/delete/', 'SlideController#deleteSlide'); // Delete Slide
});
If I try to go to /login it works well, loads all the style and js files (which are on the same folder as /admin files), it actually works 100% well.
It should redirect from /admin to /login if the user is not authenticated, but again this /admin route have no action, not even a 404 error, it just tries to load again the main page, which leads to css and js erros because of wrong path for these assets.
This only happens on Linux so I have no clue what's happening.
You could be having conflicts with your 'admin' route and your 'admin' public directory, try changing either one of those.
I have an application where there are three users, all three having separate login URLs.
Eg: https://user1.mydomain.com
https://user2.mydomain.com &
https://user3.mydomain.com
I have created the above A and CNAME records in GoDaddy to point these to my AWS EC2 instance. And also created corresponding .conf entries in Apache config to enable all these sites.
Now, since all these routes are governed by Laravel routes, I am not sure what folder to put under the sites-enabled conf file to enable the correct login page to be displayed for each sub-domain. Currently I have it like this:
# Index file and Document Root (where the public files are located)
DirectoryIndex login.html
DocumentRoot /var/www/html/mydomain/public/
My approach is correct or I need to do changes elsewhere to get this done?
You can manage the login page based on you subdomains directly in your web.php Laravel route file.
For example:
<?php
Route::domain('user1.mydomain.com')->group(function () {
Route::get('login', 'YourAuthController#loginUser1')->name('loginUser1');
});
Route::domain('user2.mydomain.com')->group(function () {
Route::get('login', 'YourAuthController#loginUser2')->name('loginUser2');
});
Route::domain('user3.mydomain.com')->group(function () {
Route::get('login', 'YourAuthController#loginUser3')->name('loginUser3');
});
References: https://laravel.com/docs/5.8/routing#route-group-sub-domain-routing
Ive just uploaded to the server and have encountered the problem that i can only see my home page unless i add www.site.com/index.php/ (index.php) after the url. Is this a frequent error for laravel and what is the fix?
Laravel not call url *.php , *.html
you can call index.blade.php from route
routes/web.php
Route::get('/', function () {
return view('index');
});
I am receiving a not found error for an existing laravel route
web.php:
Route::group(['middleware' => 'admin'], function () {
Route::get('/admin', 'AdminPageController#home')->name('admin-home');});
And when I try to access '/admin' in the url it says that it is not found, but all other routes were working fine.
I figured out the problem
It was that in the /public folder I had an /admin folder in which I placed my assets for the admin part of the site. I removed it and placed my assets inside /css/admin folder instead of /admin/css and the error was gone.
I have weird behaviour in laravel 5, it redirects me to root when put customers in url.
like this:
localhost:8080/easy_marketing/public/customers
it redirects me to
http://localhost:8080/customers
also,
when use words like those: customers_, customer, _customers they worked fine.
another links like
localhost:8080/easy_marketing/public/groups
localhost:8080/easy_marketing/public/keywords
they are working fine.
routes.php
Route::get('/', 'WelcomeController#index');
Route::get('home', 'HomeController#index');
Route::group(['middleware' => 'client'],
function() {
Route::get('customers', 'users\CustomersController#index');
Route::get('customers/import', 'users\CustomersController#import');
Route::post('customers/run-import', 'users\CustomersController#runImport');
});
Routes cannot have the same name as any folders in your public directory.
Laravel will redirect to the root if you try to access a route when you have a folder with the same name in your public folder.
Credit to user #Lazirro for his answer here: Laravel slash after url redirects to root folder
I re-name customers folder in public folder and the link is working ok.