How to include complex Vue app inside Laravel - laravel

I have a Laravel project, which should contain different Vue apps.
Some of these apps are quite-complex (stand-alone app.js file with its own components).
How can Laravel manage different vue apps, each one with its own app.js file and components?

One approach to solve this problem is to write vue apps as SEPARATE projects (using only frontend technologies) which connect with laravel using RESTful API.
This is in fact simple micro-services architecture (which include the hard separation between frontend and backend code). If you decide to do it, you will face CORS problem (but don't worry - you will find many solutions on internet e.g. this) because the vue app will be on different domain/subdomain that your RESTful laravel API.
Laravel support create restful API controllers - cmd:
php artisan make:controller API/MovieController --api --model=Movie
routing routes/api.php:
Route::group(['prefix'=>'v1'], function() {
Route::apiResource('movies', 'API\MovieController');
...
});
It is good to use for api authentication Laravel Passport (oauth2)
You should also build your separate vue applications using some modern frontend technologies like webpack, nmp (here is some example but you will probably find better)... long story - but this is good direction :)

Related

Laravel Debugbar with laravel api routes

I have a Laravel API.
The front end application is completely separate from Laravel.
All Laravel routes are located in routes/api.php
Is there any way to make the Laravel Debugbar work in this case?
https://github.com/barryvdh/laravel-debugbar
barryvdh/laravel-debugbar needs to be installed on your Laravel project (actually all debuggers need to be present within the project to audit every request) and get its files served to the frontend to work (edit repsonses with Middleware/InjectDebugbar.php).
I won't say that it is impossible to get its insights on a separate front, who knows if you are ready to fork the project and communicate with the debug bar APIs.
For a simpler alternatives you can use:
laravel/telescope docs repo
Clockwork browser extension website repo
spatie/laravel-ray(paid) website docs

Few questions when it comes to building an e-commerce website in Laravel and vue

I have a few questions regarding building an e-commerce website. I want to program a small e-commerce website using Laravel and Vue. I know the basics of Laravel and Vue, but I'm struggling when it comes to selecting the best plan to program the website. So I have a few questions regarding that.
Should an e-commerce website be dynamic or SPA?
Should I use a Vue router or built-in Laravel router?
Is it good practice to mix Vue components and Blade Template or should I separate Vue and Laravel when it comes to the frontend?
Suggest you use nuxt universal, cuz need seo, spa didnt index well in search engine
For client side use Vue router, for rest api use laravel router
If you use vue + nuxt dont need blade

Vue and Laravel separate app - Need feedback on architecture

I need a bit of expert feedback on this please as I do not want to start my project in the wrong way.
I would like to keep my Vue code separated from Laravel, the reason being, I may use this vue app later on on Cordova.
First question:
I understand how to host the Laravel API and Vue app on 2 different domains, no problems at all but I am unsure on how to setup the folder when both apps are on the same domain.
I know that Laravel should be hosted below the public_html folder and have a symlink to the public folder for security purpose. But where should my vue app goes?
Second question:
When I save images from Vue(as I am creating a blog) the images are going to the Laravel store/images folder, so each time I want to show an article in my vue app, the API must each time request the content(text and images) from the Laravel API, is this fine? Will the Google bot be able to trigger the API request when requesting the content?(I actually never thought of this...)
Thank you so much!

Connecting VueJS with laravel

Me and my co-worker both are freshers and I'm doing the front-end using VueJS and he is doing back-end using Laravel.
But How do we connect both back-end and front-end to deploy the final product?
We are struggling to put VueJS project files inside the laravel project files.
We don't have idea where to put main.js, where to put routers.js store.js App.vue inside the laravel
Install Vue Js inside Laravel Project using npm,Then in your resource/assets foleder you will see the app.js, vue component. Then compile it, laravel mix will place your app.js file inside public/js/app.js. Then include it in view file.
I asked this question when I start my career as a junior software engineer. Now I saw this again randomly. We had no idea how to connect back-end and the front-end. But eventually we learned we are developing a restAPI so we host back-end and front-end separately as two projects and connect them using the restAPI. Back-end and the front-end was two identical projects. =)

how to uses ReactJS and Laravel

how to combine Laravel and React? I mean, Laravel uses blade for its view, how to change it to React instead of blade ? There have been so many Laravel and Angular tutorial, but I can't find any for React and Laravel?
Any references of Laravel and ReactJS tutorial ?
If you are using Laravel to build a REST web service (API), then you might not need Blade. You just return JSON data. Your React App can then make calls to the Laravel API for data and process it right in the browser. You don't need Blade for this.
You would use Laravel to provide the base view (index.blade.php) which would include the React JS app, but then after that all the views and routing would be handled by React.
Here's a link to get you started.
https://medium.com/#rajikaimal/laravel-loves-reactjs-8c02f8b9d1d5
I have created laravel reactjs starter project .. refer the github project below.
I am not using the mix api of laravel since I want reactjs app to be portable to any other server or standalone app
refer the link below
https://medium.com/#padmanabhavn/bringing-laravel-and-reactjs-together-8c970cb0f65d
This question seems old but I will still share my experience for others.
This tutorial and project sample may be found useful.
https://blog.pusher.com/react-laravel-application/
https://github.com/maarcz/taskman
As well as that, the solution below has worked for me in webpack.mix.js without using app.js to be mixed up with other requirements (laravel 8):
mix.js('resources/assets/js/react', 'public/js/reactJs').react()
in blade:
<script src="{{ asset('js/reactJs/react.js') }}"></script>

Resources