How can I expose my Laravel API in index.php? - php

I'm putting an app into production in Laravel for the first time. I know that index.php is the entry point to a Laravel app, but my app has no front end. It is an API with a list of routes in routes/api.php. How can I expose this to index.php (and my hosting provider)?

Related

PHP Laravel route any - best way to serve ReactJS application without asset conflict when relogging?

I have the following code in Laravel that serves a React application that manipulates history states (reactRouter):
Route::any('{any}', 'HomeController#reactLoader')->where('any', '.*');
In Laravel, how to make Route::any accept all uri's except ones containing a dot? I want to prevent Laravel remembering invalid asset routes (ex: .map file) and serving it when a user relogs into the app.
I have tried with the following regex expression (didn't work): ^[^.]*$
Successful assets are served directly using Nginx, which they don't hit Laravel router hence not a problem.

run PHP and Nodejs app together in a cPanel account

I have installed Nodejs on my cPanel Cloudlinux server.
I created a Nodejs app (Nuxt.js) for my website frotend via Software > Setup Node.js App in my cPanel account and linked it to my website root (example.com/)
Now I want to create an API PHP service (Laravel) for my website backend and place it in my example.com/api directory which it returns JSON from this address. But when I visit this url, it returns my Nodejs app page which I created before for website root.
In fact, I want the publci_html/api folder to be exclude from rendering via Nodejs server.
Is it possible?
Or should I commit some changes in .htaccess file?
Regards
I suggest you create api.domain.com as a subdomain so you can use api.domain.com (public_html/api) for the Laravel application without any problem.
But if you have .httacess in the root directory and Node.js use rewrite rules, you can also add RewriteRule code to excluding :
RewriteRule ^(api)($|/) - [L]

Laravel 5 and Angular 6 routing issue

I'm having issues when trying to consume a laravel route defined on the api.php routes. When running both (angular and laravel) independently they work fine, but I compiled the angular project and placed on laravel's public folder, changing the index.php to index.html and it loads perfectly (dashboard show's as it should etc). But the service returns an html... Not sure if this is the correct way to do this but...
Thanks in advanceenter image description here
this is not a best way to create a project with angular with laravel.
angular provide separate routing structure also laravel provide self routing.
you need to communicate both of them so you need to create a new url and send this url in you get, post.... request and receive in your laravel routing.
you need to get more information about laravel routing go here.
https://laravel.com/docs/5.7/routing

Implementing Multi-tenancy in Laravel

I am using Laravel 5.4 with having Laravel Voyager Installed.
The main requirements of the project are to have the multi-tenant domain based application i.e. app.com and {client}.app.com
I have been trying to load configurations based on a subdomain and will act subdomain as the client code
which worked fine on localhost but while I am pushing changes to live server things are not working
As a beginner in this scope, I am not sure how thing will work on the live environment, in terms of domain redirection and setting up options in middleware, or mainly how wildcard subdomain would work in laravel's subdomain routing
You can use this package: https://github.com/hyn/multi-tenant
I've used this many times and can confirm it works extremely well. As an added bonus, there's a very detailed tutorial you can use to get going here: https://laravel-tenancy.com/docs/hyn/5.x/full-featured-tutorial

Symfony2 ignore certain route

I have the following situation:
I'm running a Symfony 2 project on a server with the route www.homepage.de.
Every request to a random route on www.homepage.de will be routed to my Landing Page.
Now I want to integrate another project, an API build with Slim PHP and Swagger UI, into this Symfony 2 project. I cloned the project into the /web directory of the Symfony2 project to gurantee access to it.
But now every request I want to do to www.homepage.de/api fails because the Symfony 2 project wants to handle the request and can't find the route. Is there a possibility to tell Symfony2 to ignore every request that is send to the www.homepage.de/api route?
First of all don't add anything to web folder of your application. Just create two applications in different folders. If you want the API to be accessible through the same domain but just with /api you cen use either mod_alias or mod_rewrite to achieve this.
In your current solution it is not Symfony that is intercepting your requests. Take a look at your .htaccess. This is where the magic happens. You can always modify rewrite rules to intercept all /api requests and redirect them to your application but I would still suggest to keep those projects apart.

Categories