Laravel + Digital Ocean + Serverpilot = Domain routing - laravel

i have server from Digital Ocean. I use Serverpilot. How do i domain routing using by laravel 5.3 ?
Rweb example :
Route::group(['domain' => 'admin.developer.app'], function () {
Route::get('/', function () { return view('dash') });
});
Route::group(['domain' => 'department.developer.app'], function () {
Route::get('/', function () { return view('dash') });
});

You need access to DNS zonefile settings at your DNS provider.
Set up a catchall DNS entry (an A record for * pointing to your server address)
Your .htaccess file must be set up correctly that it catches all subdomains and renders developer.app for your routing to work correctly. (I think the default laravel .htaccess is fine)
Add ServerAlias *.developer.app to your VirtualHost config and restart the webserver

Related

API routes return 404 in laravel

I have https://tenancyforlaravel.com/ installed in laravel to make multi-tenant and it works fine for the web routes.
My problem is that when I access my APIs then I get a 404 error in tenant domains.
tenancyforlaravel documentation: https://tenancyforlaravel.com/docs/v3/routes
It says that I must put all my APIs inside api.php file and wrap them in a Route group with this middleware so I put all my APIs inside api.php file and all my APIs as below:
Route::middleware('tenancy')->group(function () {
Route::name('api.')->namespace('Api')->group(function () {
Route::post('/login', 'AuthController#login')->name('login');
...
});
and when I access it using sub.local.test/api/login then I get 404 error.
Tested for tenancyforlaravel.com V3 and it works OK.
Route::middleware([
InitializeTenancyByDomain::class,
PreventAccessFromCentralDomains::class
])->prefix('api')->group(function () {
//
Route::name('api.')->namespace('App\Http\Controllers\Api')->group(function () {
Route::post('/login', 'AuthController#login')->name('login');
...
});
Put all your API routes inside api.php as below
use App\Http\Controllers\AuthController;
Route::group(['prefix' => '/{tenant}',
'middleware' => [InitializeTenancyByPath::class],],
function () {
Route::post('/login', [AuthController::class, 'login'])->name('login');
...
});
As you haven't mentioned your tenant identifier, I am using path as identifier, so using InitializeTenancyByPath middleware. Use whatever identifier middleware you want in place of that.
Access your API routes normally as you used to do, with your identifier. As this example uses path as identifier, the endpoint will look like:
sub.local.test/api/{tenant}/login

How to route to subdomains in laravel

My route not working on subdomain:
Route::domain('sub.example.com')->middleware(['auth'])->group(function () {
Route::get('/',function(){
return 'Hi!';
});
});
I'm using a shared linux cloud host.
When I visit sub.example.com it runs host default index.php in subdamin's folder!

Adding new route to Laravel

I have the following in /var/www/html/blog/routes/web.php
Route::get('/', function () {
return view('welcome');
});
Route::get('test', function () {
return view('test', ['name' => 'Chris']);
});
If I go to http://52.214.14.137 then I see /var/www/html/blog/resources/views/welcome.blade.php.
If I go to If I go to http://52.214.14.137/test then I would expect to see /var/www/html/blog/resources/views/test.blade.php but instead I am seeing a 404.
What am I missing?
I was using Amazon EC2 and the .htaccess file was being ignored by default.
I had to change /etc/httpd/conf/httpd.conf so
AllowOverride None
Become
AllowOverride All
I then restarted Apache with the command below and then Laravel worked perfectly.
sudo service httpd restart

Laravel 5.2: url not found but router is available in windows 7 wamp server

Default route is running
for example:
Route::get('/', function () {
return view('welcome');
});
When i run this http://localhost/laracast/public
Shows outputs as LARAVEL 5
But when I add new route to
Route::get('/hello', function() {
return 'Welcome to Laracast';
});
It shows output as => url not found
I am using
1.Windows7
2.Wamp Server
3.Composer and
4.GIT BASH
what the mistake i done it
If you are changing the default route to /hello, you need to make sure you visit http://localhost/laracast/public/hello in the browser.
If you are just trying to display your own message, change the default route to:
Route::get('/', function() {
return 'Welcome to Laracast';
});
i.e. remove hello from the route and it will correctly display your welcome message when visiting http://localhost/laracast/public

Laravel 3 HTTP and HTTPS routes

I have the following code:
Route::get('/', function()
{
return 'non secure page';
});
Route::get('/', array('https' => true, function()
{
return 'secure page';
}));
What I expected to happen is that these two routes would be treated differently. The first is for http://example.com requests and the second for https://example.com. Respectively, these pages should show the text 'non secure page' and 'secure page'. What actually happens is that both show the text 'secure page'. This must mean that both routes are treated the same i.e. it doesn't matter if the request was over https or http - the same route is triggered.
I know I can resolve my issue by using if (Request::secure()){ //routes }; but that then leads me to the question what use are the HTTPS secure routes in laravel? What do they achieve and when should they be used?
I've looked at the docs, but it's not clear to me what is supposed to happen.
The documentation says:
When defining routes, you may use the "https" attribute to indicate that the HTTPS protocol should be used when generating a URL or Redirect to that route.
"https" and ::secure() are only used when generating URLs to routes, they're not used to provide https-only routes. You could write a filter to protect against non-HTTPS routes (example below). Or if you want to prevent any non-HTTPS access to your entire domain then you should reconfigure your server, rather than do this in PHP.
Route::filter('https', function() {
if (!Request::secure()) return Response::error(404);
});
Alternative filter response:
Route::filter('https', function() {
if (!Request::secure()) return Redirect::to_secure(URI::current());
});
References:
http://laravel.com/docs/routing#https-routes
http://laravel.com/docs/routing#filters
The problem is not related to HTTPS.
The documentation says,
Note: Routes are evaluated in the order that they are registered, so register any "catch-all" routes at the bottom of your routes.php file.
It means that your
Route::get('/', array('https' => true, function()
{
return 'secure page';
}));
is over-writing
Route::get('/', function()
{
return 'non secure page';
});
I was actually lead here by Spark from laravel.io and I thought I would clarify the doubt anyhow.
Regards

Resources