Nodejs developer gets blown away by Laravel
Tags: laravel, node, webdev, programming
Published: 2022-02-04 07:54:40

> "They've got docker setup upfront, that's awesome !!" - on the first day of learning laravel

I don't know what you think about PHP, but the developer experience with Laravel has been really good, and it motivates me to write this blog. 

![Laravel deveolper](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oe5blnc2tjrnca8w9041.jpeg)

### My background with other Frameworks / Libs
Most of my projects have been around FullStack Javascript / Typescript, which makes me look at Laravel from a different eye.  


## Here are the top 5 things I liked about Laravel.

### Automated dockerizing with `Laravel Sail` 
- Managing different database types/versions and switching between them for different projects gets messy.
- With Laravel Sail, you can get your laravel application and the database of your choice within a docker container in no time.
- The Best part, `sail cli` connects you with your dockerized laravel application from outside docker.

---

### Server Side Rendering with `Blade`
- If your frontend is complex, separating it out would be better and ideally `NextJs / NuxtJs / etc` would be the way to go. 
- But, when it comes to writing SSR code within your backend application, this framework really shines here. Writing SSR code with Laravel Blade is way cleaner than the `Express + EJS` duo.
- You get more powerful directives, multiple ways to nest components, custom directives, etc. If your component involves heavy logic, you can create class-based components too. 

Consider an example where you have to show some posts to a logged in user, skipping the first post. 


![With EJS](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rhxqrk0xv4ly9t7tm5uz.png)

![With Blade](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/brac4766f8wosg95smza.png)


Laravel Blade creates an "aha" moment. 

---
### Application bootstrapping and Dependency Injection
- The Laravel application instance is called a `service container`. You can bind a class instance to a `service container` as a singleton and reuse it wherever you want. 
- Laravel automatically resolves [constructor injection](https://freecontent.manning.com/understanding-constructor-injection/) and [method injection](https://freecontent.manning.com/understanding-method-injection/) (`kinda like NestJs`). 
- With `AppServiceProvider` you can easily swap out what dependency gets injected by default. 


![Bind to app](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y5a71fxj1pe0p9ov5mz2.png)

![Auto Inject](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u6l7xeu2clcszkuha90z.png)

---

### Migrations, Factories and Query Builder
- Writing migrations and seeding the database is easy. 
- Personally, I have used `Sequelize` heavily and working with migrations in `Sequelize` has some initial learning curve.
- I found laravel migrations cleaner. Also, laravel has out of the box developer-friendly query builder, like `TypeORM` but more flexible.

Consider the example below where we want to include relations Author, Category, Comments with a Post table and filter the results by Post body and Category name.

![Laravel Query Builder Example](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oup7zazm71dh56x22f3u.png)
 
---

### Top-notch support for `miscellaneous requirements`.
- With NodeJs frameworks, adding(and updating) npm packages is more frequent, you usually install an npm package for any miscellaneous requirement. 
- Laravel has inbuilt/supplemented support for authentication, request validation, cron jobs, mailing, event handling, http requests, notifications, caching, file storage, OAuth etc.

The above reviews were solely based on developer experience. Laravel is relatively slower than other backend frameworks, but it does fine for most of your requirements.     

There's something unique to learn from every framework (I learned some new design patterns in Laravel) and it's important to not get attached to the one you are using.

---

### Hiring Alert
I work as a Software Engineer Intern at ClearGlass, we are a Cost Transparency company based out of London, UK.

ClearGlass is looking for Senior Software Engineers for the Engineering team. Most of our tech stack is in NodeJS / PHP. Know more about us and apply [here](https://clearglass.com/careers/). Learn about our tech stack [here](https://stackshare.io/clearglass/clearglass) 
See you there 👋.