I’ve just finished my first practice project with Laravel, which is a blog.
It took me more time to finish than I expected. It took about two months put together, I think, and that’s because:
- I’m not the sharpest pencil in the box when it comes to learning things like programming. I usually get the hang of it but at a slow pace.
- I tried out different stuff and approaches.
- I tried my best (as I always do) to implement best practices, not just follow the courses/tutorials, which, in most cases, are only for demonstration purposes.
- I got stuck a lot, sometimes for days.
So, now that I’ve finished my first practice project, I wanted to share with you an overview based on my beginner experience.
Before Thinking of Starting to Learn Laravel
It goes without saying that if you want to learn a PHP framework, such as Laravel, you should first learn PHP (procedural) and then PHP OOP.
You should also do a bit of research on how the MVC design pattern works.
If you didn’t learn those first, then you definitely shouldn’t start with a PHP framework, because:
- It doesn’t make sense;
- It will be A LOT harder or even impossible to understand.
So, Is Laravel Easy to Learn?
If you didn’t have much trouble learning PHP/PHP OOP.
If you’re sharp-minded and understood the logic fast, then it will be easy for you to learn Laravel.
Some people are just natural when it comes to programming.
If you’re like me and had a hard time understanding PHP/PHP OOP.
I still have trouble with the logic sometimes. The penny doesn’t drop that fast for me. 🙂
I’m not a natural, so I had to work harder and more.
Anyway, Laravel makes a lot of things a lot easier for you, but it won’t spoon-feed you. You still have to understand the environment and how it works.
And it’s a big environment.
Laravel has a large documentation
While Laravel does have a large documentation in place, it’s not that comprehensive for PHP and framework beginners, especially those that don’t catch on fast, like me. 😃
You won’t find details or in-depth examples.
90% of the time when I went through it, I didn’t understand much, so I had to google what I needed to find out.
Laravel has a large community
Laravel is one of the most used PHP frameworks, therefore you’ll find a lot of tutorials, forum threads, and people that you can ask for help.
Unfortunately, when it comes to tutorials and forum threads, things aren’t that bright because:
- A lot are outdated, using deprecated or obsolete features.
- The answers/tutorials are based on a code or format that will most likely be completely different from yours. For example, if a tutorial adds the code in Routes (web.php) for demonstration purposes, it can be challenging for you to find out how to make that code work if you’re using a Service layer.
- They might use bad practices (e.g. a tutorial or forum answer with queries in the Blade view).
Don’t get me wrong. This is not something specific to Laravel. I believe it goes for every framework.
The best way for you to find a quick answer based on your code is to ask on a forum.
Unfortunately, Stack Overflow is basically the only forum where you can get an answer in a timely fashion, but they can be pretty toxic and nuke you for not asking perfectly.
I try my best not to ask anything there anymore. I rather spend 3 days to find a solution myself, which I did, more than once. 😃
How Long Does It Take to Learn Laravel?
I’m not a fan of “it depends” answers, but it depends. 😃
It depends on:
- If you’re sharp-minded or a slow learner like me when it comes to programming. If you struggled to learn PHP/PHP OOP, then there’s a pretty big chance you’ll struggle with Laravel, too, thus taking more time to learn.
- How many hours does the course you take have.
- If the course is updated or outdated. If it’s outdated, then some things won’t work anymore, and you’ll have to spend time figuring out why and with what to replace them.
- How many times you’ll get stuck. I got stuck A LOT of times. Even the smallest typo can keep you stuck for hours.
- If the instructor provides support or you’ll have to find answers yourself.
- If the instructor teaches you best practices (most likely not) in their course, or you’ll have to spend time learning them afterward.
- If you will learn/practice daily or once every few days, which will affect your progress.
How long did it take me to learn Laravel?
Well, the course I took from Udemy had 32 hours.
But, trust me, you won’t finish in the same amount of time unless you’re watching it like a movie, without writing and trying everything yourself along with the instructor.
On average, I spent like 4-5 hours for every hour of course.
I guess I can say that I spent around 160 hours in total.
So, spending around 5 hours per day, it means I spent around a month learning Laravel.
Then, around 2 months of practicing and researching.
So, in total, around 3 months.
If you see someone saying that you can learn it in 2 weeks or something light like that, they probably are:
- Doing it wrong, therefore thinking it’s easy. As in writing the logic in Routes or Blade views.
Tips on How to Learn Laravel
1. Use a proper environment
When I was working with Laravel, there was no Sail for Docker, so I used Homestead.
The Homestead environment is a Virtual Machine that comes with a lot of prepackaged stuff that you’ll need, and it’s very similar to the production environment.
It needs a little bit of configuration, which can be annoying at first, but it’s worth it. Once you get the hang of it, it will be a piece of cake.
You’ll also get the hang of CLI (Command-line Interface) a bit, which will prove useful if you’re planning to use a VPS or Dedicated server, GitHub, and so on.
No more child’s play with cPanel, phpMyAdmin or whatnot. You’re a web developer now! 😃
I didn’t even install a GUI to handle the database (e.g. MySQL Workbench). I like working with the CLI, even though it takes a bit more time, of course.
When I see that white, simple text on a black background, it makes me feel like a true developer. 😃
I don’t know, I’m just stoked! 😀
2. Find an updated course
It’s important that the Laravel course you take is updated by the instructor.
If the course is using Laravel 5.6, for example, and the instructor hasn’t updated it, certain things could be deprecated or obsolete in the latest version.
So, what works for the instructor might not work for you. Therefore, you’ll lose time on debugging and figuring out what has changed.
Moreover, you won’t get to learn the new features. There are a lot of new and useful features with every Laravel release.
3. Try to find a course that teaches you best practices as well
To make things easier and quicker (mainly for them), most, if not all instructors won’t show you the best practices, especially when it comes to design patterns – where the business logic goes.
They’ll either add the logic in Routes, which is the fastest but most horrible way, or in the Controllers.
The latter is an ok and acceptable method. And it’s also fine to learn things step by step, without jumping into complicated stuff right from the start.
But the bad part is that you’ll have to:
- Find out on your own what the best practices are.
- Try to make them work based on what you’ve learned so far.
So, for example, trying to transition business logic from the Controllers into a Service or Repository design pattern can become challenging and frustrating.
4. Watch lectures daily and try/test everything
Try to take the lectures from the course on a daily basis, otherwise, you’ll start forgetting and it will set you back. Thus, taking even more time to learn Laravel.
Also, follow the instructor and write everything down in your IDE (I recommend Visual Studio Code - it’s free).
Try out the code on your end, get suck, fix errors. That’s how you’ll learn better and faster!
Don’t just watch the lectures like you watch “The Avengers”.
5. Try to learn and apply best practices
As I previously mentioned, you’ll most likely won’t learn best practices from your Laravel instructor. So, you’ll have to learn them yourself.
It will take time, and it can be frustrating, but that’s what it takes if you want to better yourself as a web developer.
But keep in mind that there is no perfect way of doing things.
While doing research, you’ll see a lot of disagreement on everything. You’ll rarely see web developers agreeing on something.
But, after you do a lot of research, you’ll start noticing what the majority agrees on.
For example, after a lot of research, I think I found out what’s the best practice that the majority agrees on when it comes to design patterns in Laravel.
Here’s a top with the most common ones:
- Repositories – but this is usually used when:
- You have a complex, large project;
- You work in a team;
- You don’t use Eloquent ORM;
- You think there’s a chance that in the future you might want to change the database management system (e.g. from MySQL to MongoDB). With Eloquent, it’s easy to make the change, but without it, it’s not, unless using Repositories.
- Service layer – It’s easier than using Repositories, it’s a good choice for small to medium projects, and it’s a better practice than using Controllers. I’ll explain a bit below.
- Controllers – The most common method that you’ll see in most courses, tutorials, and Laravel users’ code.
- Models – You won’t see it that often, but many still use/recommend this method.
There might be other design patterns, but these are the most common ones that I found while researching the matter.
So, even though most Laravel users write business logic is the Controllers, the majority of experienced Laravel users don’t recommend it, and for good reason.
While it’s easier and more convenient, it’s best not to cluster your Controllers with all sorts of logic because:
- It’s not really their job. The Controllers should normally only request and return data.
- You’ll end up repeating yourself. For example, if you need to find a user by id in 3 different Methods, you’ll have to add something like this in each one:
- If you need to make a change to a code that repeats itself in different Methods in the Controller, you’ll have to do it in every Method.
So, it turns out that it’s not very practical to add the business logic in the Controllers. Unless your project is small, you won’t repeat yourself, and you won’t be making significant changes often.
Instead, create a
Services folder in the
app folder and add Services for the Controllers where you add the logic.
For example, here’s how the
index() Method looks in my
And here’s how the
getAllUsers() Method that I’m requesting in
AdminUserController looks in my
You could also create reusable Methods for similar business logic and then use them in different Controllers, so you won’t have to repeat yourself.
Also, if you’ll need to change something in the future, you’ll only have to change it in one place, not 10 or whatever.
So, is this a better practice? Yep.
6. Read the Laravel docs, forums, tutorials – do a lot of research
After you’ll finish the course and start working on your first practice project, start doing research to see how you can improve it.
Read the Laravel documentation and do research on different things, such as security, performance, best practices, etc.
Usually, before sleeping, I take my tablet and do research to find out more about what Laravel has to offer, what can I do to improve my code, and so on.
On your practice project, you’ll end up doing things A LOT different from your Laravel course.
My practice blog is, like, 80% different from the one that was created in the course.
I used a Service layer, Polymorphic relations, Authorization with Policies and Gates, Eager Loading, and more.
7. Practice daily
It’s important to practice daily because your brain didn’t quite store the knowledge very well yet. It needs practice to do that.
So, if you don’t practice very often, you’ll forget things extremely fast.
Create a blog
I think that the best project you can start with is a blog.
A blog lets you practice the CRUD, Authorization for different roles, Polymorphic relations, Authentication, and more Laravel features.
Use the techniques taught by the instructor first
Start your practice with the techniques learned from the instructor because you’re familiar with them and it will help you get the hang of things easier.
Then, gradually, after doing some research, start refactoring and improving your code.
For example, I started creating my practice blog by adding business logic in the Controller, as I learned in the course.
Then, gradually, after doing research, I started improving, refactoring, moving the business logic in a Service layer, and so on.
8. Learn and practice in a quiet and distraction-free environment
It’s very important that nothing distracts you. No phone, no Facebook, no cats jumping on your keyboard, no nothing.
Just you, alone in a quiet room, with your course or practice project.
You’ll have a hard time assimilating information if you keep getting distracted.
9. Don’t learn, practice, or debug when you’re tired, stressed, etc.
It’s important to be fully focused in order to fully understand what you’re doing. Otherwise, you’ll just lose time.
Therefore, don’t learn, practice, or debug when you’re tired, stressed, or in another psychological state that could prevent you from being 100%.
For example, one day, I was practicing for several hours and I was getting tired. So, I wanted to wrap up, but I got stuck on something.
Of course, it bugged me, and I wanted to get it fixed to sleep well. 😃
So, I tried for several hours, but I couldn’t fix it.
Eventually, I let it go and went to bed.
The next day, when I was fresh, I fixed the issue right from the first minute, right from the very first try. It’s like I knew how to do it all along. It was so obvious.
But, because the previous day I was trying while being tired, I couldn’t figure it out for the life of me.
I think it’s best if you don’t learn or practice more than 5 hours per day. That’s when I usually start to get tired.
Some say that 3 hours per day is the best approach.
Just stop when you’re starting to feel tired. That’s the important thing to remember.
10. Take small breaks
Take small breaks, especially if you get stuck on something for a while.
You’ll be amazed at how a quick break can reboot you and set you up with a fresh pair of eyes to spot those problems in your code.
11. Don’t ask for help quickly
I know how incredibly frustrating it can be to spend hours trying to come up with some code or fix an issue.
And I know how tempting it is to ask for help just to get it done and move on.
But, by finding out things yourself and solving errors on your own, you’ll learn A LOT more and you’ll become more skillful.
I got stuck twice for 3 days straight while practicing Laravel.
One time, I gave up and asked on Laravel.io, but no one answered.
Eventually, I managed to find the solution myself.
What’s my “stuck” record?
I got stuck one week trying to paginate some filtered results while practicing PHP OOP.
I asked on Stack Overflow, but I only got nuked for whatever reason.
Eventually, I found the solution myself once more, and I learned a lot from it.
Now, I’m not saying to stay stuck for several days or a week until you figure it out yourself.
Sometimes, you just can’t. But at least try everything that comes into your mind until you run out of options. Then ask for help.
12. Don’t give up
This is the most important thing! It’s also the only thing all developers agree on, I think. 😃
You will get frustrated.
You will get pissed off.
You will want to quit.
If you really want to do this, if it’s really your passion and dream, then keep on pushing.
Eventually, you will make it, no matter how hard it is or how many times you fail.
I wanted to quit 3 times by now. I got up from my chair and said: “Fuck this, I’m done!”.
But, the next day, I came to my senses and looked at my screen full of errors again. 😃
That’s a Wrap
I hope this post has cleared things up for you. I hope the tips were useful, too. And if you want to start learning Laravel, I wish you a smooth journey! 😀