Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to install Ionic with a Laravel backend?

I have an existing webapp built on Laravel. I am moving to an Ionic build to create the native version. How would you suggest I separate my views, and how do I call the routes? Has anyone any example.

Here is what I am about to do: 1. move all my views to the public folder 2. install Ionic in the public folder, 3. Using UI-route & Angular make $http calls to the backend.

Thanks for your input :-)

like image 639
commandantp Avatar asked Jan 09 '23 02:01

commandantp


1 Answers

You can't simply do that.

If you have a "classic" Laravel app with blade templates, what you need to do is to expose an API from it.

Then you create an ionic app in a different directory (they are not related, so you don't have to mix them). You just need to develop your ionic app like any other ionic app. Then in your factories where you do the request to your API, you do something like:

$http.get('https://example.com/api/foo')

Where example.com is the domain of your Laravel application (You are going to need to activate CORS in it).

You just can't simply create an ionic app inside laravel, because that application will be built into an .apk to be installed on the phone and you can't add Laravel inside the package.

So the TL;DR is having your normal Laravel app where it lives, add it some public API so your ionic app can access it and then build an Ionic app from zero that will use that API.

like image 84
Jesus Rodriguez Avatar answered Jan 21 '23 22:01

Jesus Rodriguez