LARAVEL Sub Domain Routing Not Executed - laravel

Hi there i have some stupid mistake in configuring laravel.
First of all, this is my structure of folder
i use shared-hosting service and i place my laravel app, vendor and bootstrap into lib folder outside the htdocs (public/public_html) folder
so basically:
var
public_html
www
lib
-app
-bootstrap
-vendor
i create two subdomain called console for client and panel for admin
so i could call the subdomain specific url to access the system
this two subdomain is placed inside the public_html
public_html
-console
-panel
Then i move the public folder from laravel original into console folder (subdomain) with all the content from public folder (index.php, .htaccess, etc.)
Console.myDomain.com is working perfectly.
Now i want to create the admin system from the panel.myDomain.com i have created the subdomain and place all assets files (css, js, etc.) and change the routes into:
Route::group(array('domain' => 'panel.myDomain.com'), function(){
Route::get('/', function()
{
return View::make('admin.index');
});
});
but the page only showing blank page, (the blank page is shown because i place index.php file without content inside the panel folder)
additional info i have setup the bootstrap/paths.php into 'public' => __DIR__.'/../../public_html/console'
and is it require to change?
what proper way to make the panel.myDomain.com execute the routes and showing the right blade i have made?
thank you.

Related

Route /admin trying to load main page on server

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.

How to Display Corresponding Login Page for user in Laravel?

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

Access images in public_html from a subdirectory Admin - Laravel

I am using shared hosting (cPanel) to host my website (Developed in Laravel 5.4). I have another instance of Laravel 5.4 as an admin which is within the public_html folder. Both work fine as a separate instances but I can't upload/view/delete images through admin which is 1 step deeper in public_html folder.
Current directory structure
/root
/- .cpanel
/- examplewebsite.com (laravel instance)
/- public_html
/- img
/- js
/- css
/- admin (laravel instance)
So when I am in examplewebsite.com and I use asset("/img/some_image.jpg") it works fine <img src="http://examplewebsite.com/img/sample.jpg"> and point to the img folder with in public_html but for admin panel it points img folder with in the admin panel so it becomes <img src="http://examplewebsite.com/admin/img/sample.jpg"> (which is correct) but is there a way or best practice through which I can access images in public_html from admin (laravel instance).
PS: There are similar questions but I couldn't find the answer. Please advice, thanks in advance

Laravel 5 - Loading Public JS / CSS / HTML Files From Custom Folder?

Laravel serves client side (HTML, CSS, JS) files from the /public folder by default. I am currently transitioning a Blade based front-end to an Angular based one. As a result, I am mixing Blade templating with Angular templating. I am using Blade layouts to generate a navbar, footer, and other common views while I transition the body content of my pages to Angular.
I have a folder constructed just for storing Angular files. My current app structure looks something like this:
-MyApplication
-angular
-app
-bin
-bootstrap
-config
-database
....
Is there anyway for Laravel to load my assets - stored in the /angular folder? I want to keep all my Angular files in one place, in standard Angular structure, as opposed to spreading them out and placing them in the /public Laravel folder.
You can try to create a symbolic link inside the public directory to your intended angular directory. Open your terminal and create a symbolic link like so:
ln -sfv ~/path/to/MyApplication/angular ~/path/to/MyApplication/public/angular
Don't forget to update the ~/path/to/MyApplication to your actual Laravel directory. Now you may refer to the javascript file inside the angular directory like this on your blade template:
<script src="{{ asset('angular/app.js') }}"></script>
Hope this help!

I have weird behaviour in laravel 5 it redirects me to root when put customers in url

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.

Resources