I have been invited to collaborate on a laravel 7 project and I have been able to set up the project locally on a windows 10 system using wamp server. While reviewing the project, I noticed the plan is to use subdomain routing. I am currently tasked with setting up the blade templates and I want to test the route but I can't get the route to work correctly even though the routes exist. This is what the routes look like
When i try viewing the page for realestate by calling the url like this realestate.localhost:8000 I get the connection error below
The route is inside routes/realestate.php folder and its using a closure
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return 'Realestate Routes';
});
What is the right way to call the route in my local enviroment on windows?
I'm not sure if your environment is different from mine, but make sure you're accessing via http:// and not https://
I just saw your Route code - it's been a long day, sorry :P
Try reading up on Subdomain routing here.
Your Route should look like this:
Route::domain('realestate.localhost')->group(function () {
Route::get('/', function () {
return 'Hello, world!'
});
// all other routes for realestate.localhost go in here
});
You need to edit your hosts and add redirect to localhost from your subdomain. see https://stackoverflow.com/a/56921347/11775360
Related
I created a project locally and tried to upload it to a free hosting service called altervista.org.
If I call the main page it works correctly while if I call another page it gives me http 404 error.
Link to the main page
Link to a secondary page
The code of web.php
Route::get('/', function () {
return view('welcome');
});
Route::get('/firstpage', function () {
return "Hello in firstpage";
});
Can anyone help me?
Laravel doesn't work out of the box on sub folders. In order to get it working as-is, you have to host it on your document root (http://matchreferee.altervista.org/). If that's not possible, you can search on how to host laravel on a sub folder.
I am redeveloping a core-PHP web app to Laravel 5.8 application with (example) main domain: www.maindomain.com, and few route groups based on url prefix:
www.maindomain.com/user
www.maindomain.com/admin
www.maindomain.com/teacher
The app also has around 50 addon-domains, in the old app, all of them were pointing to one location (example: public_html/addondomains), and the content that was displayed was determined by the $_SERVER['http_host'].
I want to do the same in Laravel, but i can't set up the route rule for the addon domains. So, it needs to route any url that is not maindomain.com to a controller function. Any help? :)
You can use Route::domain()
Example:
//http://www.maindomain.com/test
Route::domain('www.maindomain.com')->group(function () {
Route::get('/test', 'HomeController#test')->name('main.test');
});
//http://example.maindomain.com/test
Route::domain('{addon}.maindomain.com')->group(function () {
Route::get('/test', 'AddonController#test')->name('addon.test');
});
https://laravel.com/docs/5.8/routing#route-group-sub-domain-routing
Make sure you server is configured to serve these domains from single Laravel installation.
I have experience using .htaccess files to redirect user requests from one place to another. However, I am new to Laravel and have never attempted to do redirects in Laravel.
What's the best way to do redirects in Laravel? Is it as simple as putting an .htaccess file in the project root and doing things like I normally would, or does Laravel have a special way of doing this?
For my specific use case, I want to redirect requests to images in an img directory to another publicly accessible path.
Thank you.
Laravel has a helper function for redirects, here are some examples:
Route::get('dashboard', function () {
return redirect('home/dashboard');
});
or from inside of an controller action:
return redirect()->action('HomeController#index');
Official Laravel Redirect Documentation
Everything is available at Laravel Documentation but you need to look at it. In your case you can use global redirect helper:
Route::get('route', function () {
return redirect('anotherRoute');
});
I've been going round in circles on this.
We wrote a CMS system in Laravel 3 using a bundle.
Time has come to develop a new one using latest Lavarel 5.6 and that mean packages.
We want to be able to define our own routes in web.php but everything that is not defined is picked up by the CMS package routes file so it can check if there is a page defined in the CMS and return the correct view.
In L3 this we did:
Event::override('404', function() {
...magic
In laravel 5.6 you can't do this so i've tried all sorts of:
Route::any('/{any}', function ($url = false) {
})->where('any', '.*');
But the issue is Laravel loads all the routes files in memory and the /{any} route overrides any of the routes defined in web.php, regardless of the order the service providers are loaded and we want to allow routes to be defined but to mop up anything that is not already defined.
In L4 it looks like you used to be able to do this:
App::missing(function($e) {
But again that's not possible in L5
I could possibly run it though an exception handler, but I want this to work in the package so its easily installable, and I haven't been able to make this work either!
Any help would be appreciated.
// other routes redirected to login
Route::get('/{any}', function () {
return redirect('/login');
})->where('any', '.*s');
try this route
So if you go here you will see the EXACT SAME ISSUE word for word that i'm having...
Basically I have the admin route set like this:
Route::get('/admin', function () {
return view('admin.app');
});
Simple enough right? It always returns this error here:
Not Found
The requested URL /admin/ was not found on this server.
If i change the route to /admins (plural) or really anything else, even /test the route displays properly.
I DID have an admin folder inside my public folder, but I have since deleted the admin folder and now the problem is still persisting. I don't really understand why. I'm running on a Laravel/Homestead environment. Basic LEMP stack. Nothing special.
Edit: When i type in mysite.dev:8000/admin it directs me automatically to mysite.dev/admin (Notice there is no port) So, now i'm really even more confused. :/
Edit 2: Changed the route to admin/dashboard works just fine. Could it be possible that Laravel has defined the /admin route as a 'reserved route' or something (similar to reserved keywords in any programming language) to where it won't ever display anything? Is that even a thing?
Route::get('admin/dashboard', function () {
return view('admin.app');
});
Any ideas?
delete or rename admin folder in public and run
php artisan cache:clear
I think you have admin name folder in your public directory if you remove that it will work enter link description here