Laravel is a great framework with fantastic documentation - but it can be a little overwhelming. There are so many ways to accomplish the same task. How do you know which way is the best?
This course will break down the most important things to learn about Eloquent, the ORM that is a central part of Laravel. There are 14 Lessons that take about 10-15 minutes each to accomplish.
At the end of the three weeks you will have a solid workflow and be able to use the Artisan tools to quickly design and create new applications.read more...
Julien Pauli, PHP contributor and release manager, details what changed between PHP 5 and PHP 7, and how to migrate and make effective use of the language optimizations. All statements are documented with specific examples and Blackfire profiles. Fourth episode: References mismatch generating no overhead.
The following is the 4th episode of our blog series on PHP 7 performance improvements, detailed by Julien Pauli PHP Contributor and Release Manager. We will update this introduction with links to all other articles when they are published.
Read episode 1: Packed arrays
Read episode 2: ints/floats are free in PHP 7
Read episode 3: Encapsed strings optimization
Reference mismatch happens when you pass a non-ref variable to a function argument passed-by-ref, or the opposite. Something like this:read more...
I want to look at two PHP functions:
exec. They’re so often thrown under the sensible-developers-never-use-these bus that I sometimes wonder how many awesome applications we miss out on.
Like every other function in the standard library, these have their uses. They can be abused. Their danger lies in the amount of flexibility and power they offer even the most novice of developers.
Let me show you some of the ways I’ve seen these used, and then we can talk about safety precautions and moderation.read more...
There are tons of reasons to do laravel development on Homestead. And though you might be convinced to use it, it is not always very simple to be “up and running” within minutes. Laravel’s official documentation on installing Homestead on Windows and Mac is pretty clear. But sometimes, the process is not as straight forward as shown in the documentation. There are a lot of 3rd party software involved and sometimes they create problems. I will be guiding you through the installation and configuration of Laravel Homestead while preventing the common errors from occurring.
after_or_equalvalidation rules (#16490)
PHP frameworks can really speed up your development process. They provide you with a stable foundation to start from, so that you can spend time developing the important parts of your application rather than reinventing the wheel.
But the proliferation of different PHP frameworks also means that there's a learning curve involved. As well as learning PHP, you need to learn the workings of each framework, or at least of the ones you're planning to use.read more...
PHP 7.1, the new minor version of PHP will be released on December 1st, with a number of new features, changes, and bug fixes. While we wait for it's release, let's look at some of the awesome features in PHP 7.1. Like,
I will also link to the corresponding RFCs for your reference.read more...
It’s widely accepted that high-level integration tests alone do not make for a good test suite. Ideally each individual component of your application should have unit tests, which test that component in isolation. These unit tests are usually much quicker to run, making it easier to practice test-driven development. However, it can sometimes be hard to grasp how to test that one component on its own.
The other day I had an issue with several middleware classes for a Laravel application and I wanted to verify that they were working as expected. Sounds like a job for dedicated unit tests, but I hadn’t tested custom middleware in isolation before, and figuring out how to do so took a while.read more...
As we already wrote that "Code Reuse By Inheritance" has lots of problems and we consider it a code smell. You should always aim to use Dependency Injection, most likely Constructor Injection. But with test cases in PHPUnit we cannot do this because we have no control about how and when our test cases are created. There are a similar problem in other frameworks, like we discussed in "Object Lifecycle Control". We also blogged about traits as a Code Smell, but let me show and explain why they might be fine to use in your test cases.
So in PHPUnit it is common to reuse code by inheritance. Even by now we often create some base class providing common functionality. This works fine and is OK if this really defines an "is a"-relationship. Let's continue with an example from our Page Object test repository. The patterns described here are usually not required for Unit Tests (which you should always also write) but mostly for integration or functional tests.read more...
Refactoring to Collections is a great book by Adam Wathan where he demonstrates, how you can avoid loops by using collections. It sounds great from the beginning, but you need to practice it, in order to be able to use it in your own projects. This is why I refactored some of my older projects. I want to share these examples today with you.
Note: Code examples are from Laravel projects where collections are built-in.
Here I needed to built a string from an array to create an unique cache key for given search filters. When you first look at the before and after examples, you could question if the collection version is a better choice here. This is because it looks a little bit more complex. But this is just the first impression. The collection version of this code has some great benefits: