Laravel Subdomain Routing 'this site can't be reached' error - php

I need to develop a project with subdomains in Laravel 7.28. I'll pass subdomain variable and check whether that user belongs to that particular domain. I have installed Xampp on local. I tried these two ways:
1
Route::domain('{subdomain}.myapp.com')->group(function (){
Route::get('/', 'CRM/HomeController#index')->name('subdomain-index');
});
2
Route::group(['domain' => '{domain}.localhost'], function() {
Route::get('/', 'CRM\HomeController#index')->name('crm.index');
Route::get('login', 'CRM\LoginController#login')->name('crm.login');
Route::post('login', 'CRM\LoginController#postLogin')->name('crm.login.post');
Route::get('register', 'CRM\RegisterController#register')->name('crm.register');
Route::post('register', 'CRM\RegisterController#postRegister')->name('crm.register.post');
Route::get('logout', 'CRM\LoginController#logout')->name('crm.logout');
});
When I type 'demo.localhost' that brings me the same content of 'localhost'. When 'demo.myapp.com' I get 'This site can't be reached' error.
Inside of CRM/HomeController:
<?php
namespace App\Http\Controllers\CRM;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class HomeController extends Controller
{
public function index($subdomain)
{
echo '1';
die();
}
}
Where did I do wrong? I tried the official way and questions from StackOverFlow but I can't see my mistake. Any help?

Related

How to setup home page without requiring auth (Laravel)

I am trying to setup a standard homepage that every user has access to (and lands on), before they are routed to other pages after logging in.
Currently the web.php setup is
use App\Http\Controllers\HomeController;
Route::get('/', [HomeController::class, 'home']->withoutMiddleware(['auth']));
The withoutMiddleware is to try and bypass the requirement of auth when trying to access the home.blade.php page, however I get the following error:
Very new to Laravel, so any help would be greatly appreciated. Cheers!
Routes don't require authentication unless it's explicitly specified in the routes web.php file or the controller.
So it can be as following:
use App\Http\Controllers\HomeController;
Route::get('/', [HomeController::class, 'home'];
Route::get('/', function () {
if(Auth::guest()){
return view('/home');
}else{
return redirect('/login');
}
});

Laravel - Not Found - The requested resource /control was not found on this server

Hi everyone I need a solution with laravel project when I try open backend admin with /control its giving me an error "Not Found - The requested resource /control was not found on this server."
When I change the name "/control" to anything like "/control5" or something its working fine but the problem is I use /control at views and other! I am new to laravel I didn't know what the problem was? please help me out with this!
Web.php
Auth::routes();
Route::get('/about', [App\Http\Controllers\AboutController::class,'about']);
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
Route::get('/', [App\Http\Controllers\HomePageController::class,'index']);
Route::get('/listing', [App\Http\Controllers\ListingPageController::class,'index']);
Route::get('/details', [App\Http\Controllers\DetailsPageController::class,'index']);
Route::group(['prefix' => 'control','middleware' => 'auth'],function(){
Route::get('/', [App\Http\Controllers\Control\DashboardController::class,'index'])->name('control');
//Pages
Route::get('/pages', [App\Http\Controllers\Control\PagesController::class,'index']);
Route::get('/pages/add', [App\Http\Controllers\Control\PagesController::class,'create']);
Route::get('/pages/edit', [App\Http\Controllers\Control\PagesController::class,'edit']);
});
DashboardController
namespace App\Http\Controllers\Control;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class DashboardController extends Controller
{
public function index(){
return view('control.dashboard');
}
}
Because, you have a folder named control on /public folder. That error occurs when you create a folder in the public folder with the same name as your route so please change the name of the folder you have put in the public folder so that it has a different name from your route this will probably solve your error

Laravel 5.7 login with Laratrust, Routing fails with wrong route to "/home"

I wanted to give laratrust a shot, but I ran into some trouble with the routing.
Let me explain in brief, what I did so far.
I've created a new laravel app as described in the laravel docs. Then I used the make:auth generator to generate everything needed for standard login/registration. That works great. Now I am on a point, where laratrust kicks in. After installation I did everything as described in the laratrust docs. Additionally I went with DevMarketer's "Build an advanced blog" series on youtube, to get laratrust to work.
The problem is now, that a login (i.e. as admin) leads me to https://myapp.local/public/home instead to https://myapp.local/public/admin/dashboard as defined so in the controller. If I edit the url after login to reach the dashboard, it works well and the dash appears. Why not after my login attempt?! Any ideas are welcome.
The urls above are just examples. So don't be confused while have a look into my "AdminController":
<?php
namespace App\Http\Controllers;
use App\User;
use app\Role;
use Illuminate\Http\Request;
class AdminController extends Controller
{
public function index()
{
return redirect()->route('administration.dashboard');
}
public function dashboard()
{
return view('backend.dashboard');
}
My routes:
<?php
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
/**
* Admin routes
*/
Route::prefix('administration')->middleware('role:superadministrator|administrator')->group(function () {
Route::get('/', 'AdminController#index');
Route::get('/dashboard', [
'uses' => 'AdminController#dashboard',
'as' => 'administration.dashboard',
]);
});
So, maybe its too late for me and I won't see my mistake. Can anybody help me out? Thanks guys. Good night.
Sorry guys,
I found the answer myself. I just saw, that I forgot to customize the LoginController.

Laravel 5 sub domain routing - Controller not found issue

I am trying my hand at creating a sub domain route for a project I am working on and I am able to get the sub domain working. However, the only time it works is if I return some copy directly from the routes.php. When I try to access a controller, it tells me that it's not found, when it's clearly there.
This code:
Route::group(['domain' => 'demo.tk.dev'], function(){
Route::get('/', 'DemoController#demoLanding');
});
Returns me this error:
ReflectionException in Route.php line 280:
Class app\Http\Controllers\DemoController does not exist
But if I do something like this:
Route::group(['domain' => 'demo.tk.dev'], function(){
Route::get('/', function() {
return 'Success';
});
});
Then that works.
I am not seeing anything in the documentation about making any other changes for the Controllers to work with the sub domain. Am I missing something? Any help would be greatly appreciated.
check if you have a DemoController in your Controller folder and check if it has correct namespace ie.
namespace App\Http\Controllers;

Laravel 5 Routing with Auth

Hello!
I'm trying to learning laravel, and i started with doing a page that only logged people can access ( I don't have login yet ) , but i'm just testing, so far i have:
Routes.php:
<?php
Route::get('/', ['as' => 'index', function () {
return view('index');
}]);
Route::get('/home', function () {
return view('home');
});
Ok, this file contains the routes , i searched how to give a name to the route, so i can redirect user to that route when he don't have access.
My other file is home.blade.php:
<?php
if (!Auth::check()){
return Redirect::route('index');
}
?>
So is that the best way to check if user is logged? I gave a name to the route, index , so if user is not logged i want to redirect back to index, is not working tho, i want to know if this is the best option to achieve my goal.
Thank you.
The best way, as said at documentation is:
Route::get('/home', ['middleware' => 'auth', function () {
// here will be only authorized access
return view('home');
}]);
Auth middleware defined by default.
use Auth; loading facades
if (Auth::check()){
if(Auth::Guest()):
return Redirect::route('index');
endif;
}
?>

Categories