1

For an existing PHP application, that doesn't make use of any frameworks... is it possible to add/integrate Laravel based authentication to it without trying to convert the entire PHP into a Laravel application?

I am a complete PHP newbie, and was hoping for someone to point me in the right direction. Much appreciated.

11
  • In my opinion it will be easier to convert entire project to Laravel. Commented Oct 20, 2016 at 2:49
  • Unfortunately that is out of the question... so I would like to know whether it is possible to simply just "add-on" the Laravel authentication code to the existing PHP app. Commented Oct 20, 2016 at 2:52
  • May be this SO question could answer: stackoverflow.com/questions/20968414/… Commented Oct 20, 2016 at 2:54
  • So it is possible? Actually, my situation is such that I need to add JWT session-less authentication to an existing PHP application. I have seen various Laravel based tutorials on the internet and was wondering whether I could just use them to add-on to my current app. Commented Oct 20, 2016 at 2:59
  • The answer is NO. If you have existing application, you have to start from scratch, and convert the entire project to Laravel. Since you're a newbie, you can start watching tutorial videos here: laracasts.com Commented Oct 20, 2016 at 3:00

1 Answer 1

1

Of course you can add JWT to your existing PHP app, it's not "locked" to Laravel, far from it. Most of the frameworks that have these capabilities built in are just supersets of various components to make life easier for developers. You can of course implement these on your own in your application, given that you have the knowledge how to do so.

Since this is a bit abstract question without any provided examples, some answers with code snippets might just confuse you. Instead here are some resources where you can read more on the subject and get going: Sitepoint, JWT in PHP App and PHPClicks Token Based Authentication.

Another approach would be to craft a new Laravel project (or Lumen project if it's only a API and you don't want to render views) and import the current codebase from the other application to it.

If you want to make life easier for you, you can use some SAAS alternative for Authentication like Auth0.

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you for that Bobeta. Actually, I was not implying that JWT is tied to Laravel. I was asking about using Laravel itself with my existing PHP API... Without trying to convert everything to Laravel. So only the authentication being in Laravel, while everything else remains otherwise.
I see.. My answer is based on what you wrote in the comment, "Actually, my situation is such that I need to add JWT session-less authentication to an existing PHP application". It's a bit hard for me to understand what you're trying to accomplish in this case. I suspect a service like Auth0 might be a better choice for your case.
Let me clarify. I want to add JWT authentication to my existing PHP API. However, to save time, I would like to make use of existing Laravel tutorials (that implement JWT) from the internet and simply use them (and Laravel as a result) with my existing API. Hence, my question about the possibility of adding/using Laravel to an existing non-Laravel PHP application. But I still don't know exactly whether I can add Laravel to only part of the code or not.
It's a bit hard to give you the right guidance since we don't really understand what the application does or how it's architectured. But generally, if that's the approach you want to take, I would recommend crating a new Laravel (or Lumen if it's a simple API) project and adding the existing PHP codebase to it and then adjust it to fit your needs. Another potential approach would be to use the relevant components you need from Symfony (huge chunk of Laravel is a superset of various Symfony components) or simply use a SAAS for Authentication like auth0.com. I updated the reply above btw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.