I am new to Laravel.
I am developing an application which is going to be an Web (laravel8 + vue.js) + Mobile App (Android).
Application has both backend and frontend on both web and mobile app.
Which means I need routes for web application to manage backend and frontend and API routes to manage same.
So, I was thinking how I should structure my code in Laravel to reduce code redundancy and what is best approach to plan my project DIR structure, routes etc.
Thanks.
I suggest you take a look at and consider using Laravel Breeze or Laravel Jetstream with the Interia.js & Vue.js stack. Here is the info: https://laravel.com/docs/8.x/starter-kits.
While both of these kits come with Inertia.js (Breeze only if you include it during installation), you don't have to use it and can use Axios or whatever you prefer.
These kits offer scaffolding with the routes, controllers, and views you need to register and authenticate your application's users and you should be able to easily build you API on top of either for the mobile app.
I used to use this:
Project
--routes
----api.php => you have API router here
----web.php => your web router
--views
----create-product.blade.php => then call to vue component
--vue
--create-product.vue
Related
I am planning a small project and have a question about authentication. I would like to implement the site with Laravel 8. However, as soon as the user has successfully logged in, he should be directed to the user dashboard. The User Dashboard should be a pure VueJS Single Page Application.
Now my question. Which auth should I use here? Session or token for the whole site or is both possible and useful?
If I use the token auth variant, for example, then I can protect the Vue app very well but I cannot access the user information outside the Vue app. For example, the current profile picture of the user should appear in the navbar and not only in the vue app but also on the landing page, contact page etc.
How can I do this and what will be the best practice and thanks for your help!
Use token based Authentication
(Laravel Passport)
Use Token-based authentication system.
In this way, you'll be able to manage the entire application UI and role checking in the frontend only. I would rather prefer to go with JWT [https://jwt-auth.readthedocs.io/en/develop/laravel-installation/]. It's easy to use and the documentation is pretty good. It's even supported by Lumen also. If you wish to integrate any micro-service in your application future, then it's available in Lumen micro-service also.
How does Inertia.js connects my Laravel backend on a domain with my Vue.js project on another domain ?
Or am I trying to do something Inertia.js is not made for ?
you answered your own question - Inertia is not for splitting the frontend from your backend. It's meant to couple the backend and frontend just like if you were to use blade.
From https://inertiajs.com:
Build single-page apps, without building an API.
Inertia.js lets you quickly build modern single-page React, Vue and Svelte apps using classic server-side routing and controllers.
I have already developed 2 applications and I want to deploy my first application which contains Vue Cli and Laravel Php framework on the main domain and the other application similarly made with Vue and Laravel in my subdomain. Please, could you suggest to me how could I perform these actions? Thanks
Here's the situation:
I have a Laravel application
there is a mobile application, to which I do not have the source code (the client had a falling out with the previous developers)
we need to build a new mobile app which does essentially the same things as the previous one
I would like to use the same routes the previous mobile app used
The thing is, I don't know which routes the old app is using.
In the routes directory we have:
api.php
channels.php
console.php
legacy_app.php
web.php
I am trying to send requests to these routes with Postman, but they always return an empty response.
I know I can go through the back-end code, try logging stuff while using the app, etc, but I would much prefer a way to reliably get a list of routes and required parameters. Is there any way at all to accomplish this?
I've a question about simplicity of a task. I'm fairly new to laravel and vue js, I'm used to php and javascript though.
I hope my question makes sense since I'm not sure if the technologies work as I think.
So I want to do a SPA project with laravel as backend, vuejs as frontend and mysql for the database. I need the site to be online and want an authentication to grant user access to different parts of the website. Let's say, you have to register yourself. If it's a normal user, he can see the "UserDashboard" and if it is an admin he can see the "AdminDashboard".
I've came across a couple of tutorials which show how to create an authentication system by using vue components to handle login/register/logout... It's pretty complicated and messy in my opinion.
Is it easier to just use laravel authentication and blade templates for authentication and then show the SPA for registered users/admins? If that's possible. Only saw the first option I mention for the moment.
Edit :
Here is a picture to illustrate last approach
Laravel authentication, then show SPA
If you use Laravel Mix, simply have one blade template that hosts your application (it's already set in Laravel). However, if you're using Laravel for API and a separate project for the front-end SPA, use Passport. Here's one of the ways to do it.
If you are using Laravel Mix, the CSRF token is already in a meta tag and is being added to Axios. All you need to do is make on blade template show your app.
You can also have separate blade views for login / registration etc and show SPA when logged in. But that's not really the best practice. Since I've figured out how to use Passport, I've always gone the separate vue project route.