SubDomain getting Internal server error in laravel 5.3 - php

i am new to laravel, i managed to deploy my laravel project on godaddy shared hosting, it works perfectly... but the domain doesnt work...
this is the nature of my routes/web.php
<?php
Route::group(['domain' => 'example.com'], function(){
Route::get('/', function () {
return view('welcome');
});
});
Route::group(['domain' => 'cars.example.com'], function(){
Route::get('/', function () {
return view('cars');
});
});
so, whenever i try accessing cars.example.com, it brings the error "500 internal server error"
guys i need your help on this one, thanks

This works for me but I am not using godaddy.
// All subdomain routes
Route::group(['domain' => 'cars.example.com'], function () {
Route::get('/', function () {
return view('cars');
});
});
// All domain routes
Route::get('/', function () {
return view('welcome');
});
If you want to get fancy you could do this.
// Captures all sub domains
Route::group(['domain' => '{subdomain}.example.{tld}'], function () {
Route::get('/', function () {
return view($subdomain);
});
});
// All domain routes
Route::get('/', function () {
return view('welcome');
});

Related

How to redirect to specific URL?

I have a route for tenants name like that:
example.test/TenantNameHere
And I want to make the default of my domain start with the word "site":
example.test/site
My code:
Route::prefix('{tenantName}')->group(function () {
Route::get('/', function ($tenantName) {
return "{$tenantName}";
});
});
Route::prefix('site')->group(function () {
Route::get('price', function () {
return view('welcome');
});
});
Route::redirect('/', 'site', 301);
The problem that I'm facing with this code now is when I open the domain it redirects me to tenantName route, not to the home page that I made!
How can spreate the route of site from TenantName ?
you just have to register your absolute path ('site') first, and "wildcards" routes after, because everything you put in url line now hit the first tenantName route
try this (reverse the order):
Route::redirect('/', '/site', 301);
Route::prefix('site')->group(function () {
Route::get('/', function () {
return view('welcome');
});
});
Route::prefix('{tenantName}')->group(function () {
Route::get('/', function ($tenantName) {
return "{$tenantName}";
});
});
also change "/site/price" path to "/site", so redirect will find correct route

Why my routing on the server does not work - with Laravel 6.0?

Normally everything works fine on localhost. When I throw the project to the server, only the homepage works.
When I add manually to this section from the database, I can pull the data.
web site here: http://elsetea.com/public (running)
but when I want to log in to my admin panel from this page (http://elsetea.com/public/login) routing does not work properly and it gives an error.
Why can you think? Please help me. Very Thanks.
Username: admin#admin.com
Password: admin
You can see some routing below.
web.php
Auth:
:routes();
Route::namespace('Frontend')->group(function () {
Route::get('/', 'HomeController#index')->name('home.index');
// Route::get('/home', 'HomeController#index')->name('home');
});
Route::namespace('Frontend')->group(function () {
Route::get('service', 'ServicePageController#index')->name('service-page.index');
});
Route::namespace('Frontend')->group(function () {
Route::get('portfolio', 'PortfolioPageController#index')->name('portfolio-page.index');
Route::get('portfolio/{slug}', 'PortfolioPageController#show')->name('portfolio-page.show');
});
Route::namespace('Frontend')->group(function () {
Route::post('comment', 'CommentController#store')->name('comment.store');
});
Route::namespace('Frontend')->group(function () {
Route::post('contact', 'ContactPageController#store')->name('contact-page.store');
});
Route::namespace('Frontend')->group(function () {
Route::get('aboutus', 'AboutusPageController#index')->name('aboutus-page.index');
});
Route::namespace('Frontend')->group(function () {
Route::get('blog', 'BlogPageController#index')->name('blog-page.index');
Route::get('blog/{slug}', 'BlogPageController#show')->name('blog-page.show');
Route::get('blog/category/{category_name}', 'BlogPageController#category_show')->name('blog-category.show');
});
Route::middleware(['auth.admin'])->group(function () {
Route::get('admin-panel/dashboard', 'HomeController#index')->name('dashboard');
});
Route::namespace('Admin')->middleware(['auth.admin'])->group(function () {
Route::get('admin-panel/profile/edit', 'ProfileController#edit')->name('profile.edit');
Route::put('admin-panel/profile/{id}', 'ProfileController#update')->name('profile.update');
Route::get('admin-panel/profile/change-password', 'ProfileController#change_password_edit')->name('profile.change_password_edit');
Route::put('admin-panel/profile/change-password/update', 'ProfileController#change_password_update')->name('profile.change_password_update');
});
Route::namespace('Admin')->middleware(['auth.admin'])->group(function () {
Route::get('admin-panel/site-info', 'SiteInfoController#create')->name('site-info.create');
Route::post('admin-panel/site-info', 'SiteInfoController#store')->name('site-info.store');
Route::put('admin-panel/site-info/{id}', 'SiteInfoController#update')->name('site-info.update');
});
Route::namespace('Admin')->middleware(['auth.admin'])->group(function () {
Route::get('admin-panel/homepage-version', 'HomepageVersionController#create')->name('homepage-version.create');
Route::post('admin-panel/homepage-version', 'HomepageVersionController#store')->name('homepage-version.store');
Route::put('admin-panel/homepage-version/{id}', 'HomepageVersionController#update')->name('homepage-version.update');
});

Function inside route group [laravel-passport]

i have some function that check something and give back in some cases "exit();".
i want to use it inside Route::group.
how can i do it right without it impact all the other routes? thanks!
Route::group(['middleware' => ['auth:api']], function() {
myFunction (); //this function can give back: exit();
Route::get('/test', 'Api\Test#test');
});
Turn your function into middleware: https://laravel.com/docs/5.8/middleware
Group the routes that must be affected by your check, and leave out the routes that don't.
Route::group(['middleware' => ['auth:api']], function() {
Route::group(['middleware' => ['MyMiddleware']], function() {
Route::get('/check-me', 'Api\Test#test1');
});
Route::get('/dont-check-me', 'Api\Test#test2');
});

Error in View Route Laravel with Virtual Host XAMPP

I'm was change my XAMPP port to 8000 and I open my virtual host with http://laravel.test:8000/
I try to add this to my routes.php :
Route::get('/', function () {
return view('homepage');
});
Route::get('/', function () {
return view('about');
});
but when I'm try to open : http://laravel.test/about:8000/ or http://laravel.test/homepage:8000/ it's error.
How can I open that page with the xampp port changed?
Define your routes properly
Route::get('/', function () {
return view('homepage');
});
http://laravel.test:8000/
Route::get('about', function () {
return view('about');
});
http://laravel.test:8000/about

Can I group multiple domains in a routing group in Laravel?

Let's say I have the following:
Route::group(array('domain' => array('admin.example.com')), function()
{
...
});
Route::group(array('domain' => array('app.example.com')), function()
{
...
});
Route::group(array('domain' => array('dev.app.example.com')), function()
{
...
});
Is there any way to have multiple domains share a routing group? Something like:
Route::group(array('domain' => array('dev.app.example.com','app.example.com')), function()
{
...
});
Laravel does not seem to support this.
I'm not sure why I didn't think of this sooner, but I guess one solution would be to just declare the routes in a separate function as pass it to both route groups.
Route::group(array('domain' => 'admin.example.com'), function()
{
...
});
$appRoutes = function() {
Route::get('/',function(){
...
});
};
Route::group(array('domain' => 'app.example.com'), $appRoutes);
Route::group(array('domain' => 'dev.app.example.com'), $appRoutes);
I'm not sure if there is any significant performance impact to this solution.
Laravel 5.1
Route::pattern('subdomain', '(dev.app|app)');
Route::group(['domain' => '{subdomain}.example.com'], function () {
...
});
Route::pattern('subdomain', '(dev.app|app)');
Route::pattern('domain', '(example.com|example.dev)');
Route::group(['domain' => '{subdomain}.{domain}'], function () {
...
});
You can pass on the domain name as well:
Route::pattern('domain', '(domain1.develop|domain2.develop|domain.com)');
Route::group(['domain' => '{domain}'], function() {
Route::get('/', function($domain) {
return 'This is the page for ' . $domain . '!';
});
});
Just in case you need to know with which domain name the controller is called.
Tested it with Laravel 5.6.
Interested in this also! I'm trying to register a local development + production subdomain route, for the one controller action.
i.e.
# Local Dev
Route::group(array('domain' => "{subdomain}.app.dev"), function() {
Route::get('/{id}', 'SomeController#getShow');
});
# Production Server
Route::group(array('domain' => "{subdomain}.app.com"), function() {
Route::get('/{id}', 'SomeController#getShow');
});
I tried:
# Failed
Route::group(array('domain' => "{account}.app.{top_level_domain}"), function() {
Route::get('/{id}', 'SomeController#getShow');
});
But it failed.
Not a huge issue, as DesignerGuy mentioned I can just pass in a function to both routes - but it would just be more elegant if they could be grouped :)
check in laravel docs, if you main domain is myapp, in production is myapp.com and in local environment is myapp.dev try using a *
Route::group(array('domain' => '{subdomain}.myapp.*'),
function()
{
...
});
according to laravel document
in laravel 5.4+ you can use this way:
Route::domain('{account}.myapp.com')->group(function () {
Route::get('user/{id}', function ($account, $id) {
//
});
});
A better answer found on Laravel discussion on the same topic is with macros. It works great for me.
https://github.com/laravel/framework/issues/4017#issuecomment-267820459
Route::macro("domain", function(array $domains, \Closure $definition) {
foreach ($domains as $domain) {
Route::group(['domain' => $domain], $definition);
}
});
Route::domain(['foo.bar.dev', 'foo.bar'], function($route) {
// Do stuff
});
Currently you cannot. I had the same 'problem'; my fix is to cycle through your subdomains with a foreach and register the routes.
see this link. http://laravel.com/docs/routing#sub-domain-routing
Route::group(array('domain' => '{subdomain}.example.com'), function()
{
...
});
or Use this package.
https://github.com/jasonlewis/enhanced-router
It help you can set where on group routing like this.
Route::group(array('domain' => '{maindomain}'), function()
{
...
})->where('maindomain', '.+\.example\.com$');

Categories