Learning php/laravel

Hello, since I’m pretty much done with learning the javascript stack, I would like to move on to learning my first new language: php.
My practical question here is: what should I learn exactly?
My plan would be to focus on backend programming and learn Laravel anyway, but what knowledge of php do I need to have first to move on to Laravel? Is it enough if I just know the very basics like variables, functions, sessions, globals etc. or should my knowledge be much deeper?

For example, I come from javascript, and I don’t think you need to be a master at vanilla javascript in order to be a decent backend programmer with node, express/nest and databases etc.
Is it similar with php and Laravel?
Thanks in advance.

1 Like

What to learn comes from why you want to learn PHP. Look at the jobs you want. What do they use?

1 Like

I want to learn php because I want to learn Laravel.

…And why do you want to learn Laravel? The context and use cases highlight what parts of the language are most important.

Likely familiarizing yourself with the basic control structures before focusing on what you actually want to learn will be adequate.

I like doing backend projects with javascript (node, express etc) , I see Laravel get’s used for that al lot aswell, so I want to learn it too, that’s why.

Just for fun?

My point here is that languages are just tools. We learn them for specific tasks or jobs. The task or job will naturally determine what parts of the language you need.

1 Like

I would preferrably use it as a backend api in combination with for example a react or vue frontend.

You are missing my point. Why Laravel and not a different tool?

I’m not missing your point, I’m trying to get an answer to my actual question instead of starting a discussion on why to use Laravel.

The answer to your actual question… like I have said over and over and over… depends upon why Laravel is the only acceptable tool for what you want to do. The specific reasons why you want to use PHP over Javascript become the specific things that you need to focus on. If you can’t articulate why exactly you want Laravel instead of Node, for example, then it isn’t possible for anyone to provide more specific guidance.

Learning a language or framework ‘just because’ is fine, but if you don’t have a specific motivation or goal for why Larvel over other options, we can’t provide that for you. The best we can offer is ‘learn the basics’.

For example, I learned Rust because I wanted to see why the memory safety and ergonomics it offered was better than my options in C. That focused my efforts on specific parts of the language. The specific project I wanted to work on further focused my efforts onto specific parts of the language.

You can learn Laravel before you learn PHP without much issues but a few weird gotchas you’ll hit and you’ll want to learn these:

  • How to use Docker. PHP is a bit of a PITA to set up locally and has some pain points that don’t exist in node. It’s more than just managing PHP versions, the language itself can be configured too and a lot of features come from extensions written in C. Learning Docker eliminates a lot of the headaches when switching around PHP projects.
  • Object accessors are done like $object->property which is weird if you come from JavaScript
  • Variables are defined with $ as the first character but if you do something like $$var that’s actually called a “Variable Variable”… go look them up in the docs
  • Accessing properties or methods statically is done like this: MyClass::staticProperty which is weird if you’re coming from JS
  • It’s not a strongly typed language and it is interpreted like JS however PHP has “type hints” built into the language. Learn about those.
  • PHP is Object Oriented… sort of but to get imports to work the way you might be used to in other OO languages you need a tool called composer and use something called PSR-4 Autoloading. You’ll want to go look up what PSR in PHP is and get familiar with their standards. Also the autoloading bit, Laravel handles for you out of the box. But you’ll want to know what it is and understand the different ways PHP can be used with autoloading (classmap is another common autoloading standard)
  • You have interfaces now! Learn how to use them.
  • Magic methods. PHP has a concept called “magic methods”. They’re super powerful and Laravel leveredges them under the hood extensively. It’s actually the most divisive practice and when you hear people complain about Laravel it’s often that they disagree with the “magic”. What they’re referring to is the heavy usage of PHP magic methods which can make code discovery and navigation difficult.
  • String concatenation is done like $str1 . $str2 which is weird if you come from JavaScript

Highly recommend using laracasts.com they’re not 100% free but there’s lots of free courses like these:

https://laracasts.com/series/object-oriented-principles-in-php

https://laracasts.com/series/php-for-beginners

Laravel Stuff to Learn

  • Start with Laracasts and follow along the free material there
  • After you’re comfortable with the basics of Laravel the next most important thing to learn is the IoC container and make sure you understand Dependency Injection.
  • Laravel also utilizes a few design patterns in the framework so understanding the patterns may help you understand the framework better
    • ORM which you may already be familiar with is a pattern for talking to databases without writing raw queries
    • The ORM that Laravel uses is called Eloquent and it is an implementation of the “Active Record” pattern
    • The architecture of the framework is MVC (model, view, controller)
    • Eloquent also provides access to what’s called a Query Builder and follows the very popular Builder pattern
    • Most core services and tools in the framework are available as a Facade which is a controversial pattern sometimes called an anti-pattern but learn about it and you’ll Laravel addresses most of the concerns by making them easy to test

Hopefully that gives you a good start. Good luck!

1 Like

I feel compelled to point out that you can’t realistically be done learning JavaScript. It’s ever-evolving and building a back-end via Node/Express can get very complicated. And there are TONS of Node frameworks that you could learn. If you want to learn an opinionated Node framework (because for all intents and purposes, Laravel is opinionated as well), there are plenty to choose from.

As someone who uses PHP professionally (and has used Laravel in a previous job), it’s not something I’d recommend for casual learning. PHP isn’t a very intuitive language necessarily, and Laravel is a complicated framework. And even though it is the most prolific PHP framework, it’s not really that prevalent in the industry either, compared to other languages/frameworks like Rails especially.

If you want to learn something other than JavaScript for back-end, Ruby and Rails would be much better uses of your time. Rails has a huge community, widespread adoption in the industry, and it’s very commonly used with React. And you’ll have an easier time learning Ruby since it has similarities with JavaScript. Additionally I’ve heard Rails and Laravel are roughly on par with each other (i.e. opinionated “batteries included” frameworks).

1 Like