Nowadays, you’d be hard-pressed to find a PHP developer who doesn’t know about Laravel. If you are one of these people, visit the Laravel site ASAP! The framework is insanely popular in the PHP community these days because of the thought that has gone into it to make it easy to use and robust as hell! We will demonstrate its easy-of-use by building an admin interface that we can use to manage our users in some fake application we have already built. Let’s do it!
Sometimes, we want to query the WordPress database for all of a post type based on some custom fields we have set. WordPress makes it easy to do. However, the syntax can be kind of cryptic due to its usage of multidimensional arrays. Hopefully, I can help clear it up for you a bit.
When creating a class, it is necessary to not only think about the functionality of the class but also how a developer will interact with that class. Making a class API easy to use is well worth the effort. Luckily, PHP ships with quite a few magic methods that can make creating a class API much easier to do. In this article, I will be talking about three of them — __get, __set, and __toString.
Not long ago, I wrote a post about Adding Roles to Laravel Users. I like my custom solution, but I figured there had to be a better solution out there. Honestly, I should have done some looking for information before I built it. Anyways, I stumbled upon a package called Entrust written by Zizaco.
Yesterday, I updated my computer to the new release of the amazing OS X operating system from Apple, code-named Mavericks. Everything went smooth, but then I realized it wiped my PHP installation away and gave me the default Mavericks installation, PHP 5.4.17. Being a web developer, I like to have the most recent version of PHP whenever I can. So naturally I decided to recompile it. I have done this many times before after upgrades, so this wasn’t anything new to me.
For some redirect functions in Laravel, such as Redirect::back(), a URL must be passed in your headers so the framework knows what URL to redirect back to. When testing routes that only redirect back to the previous URL, this can be confusing since there is no previous URL. It must be sent manually.
Sometimes a view will need a variable every single time it is loaded. Perhaps we are developing a system for tracking users, and we want to display the number of users registered in our system next to a button to display the list of users. If we have a resource controller for our User model, we would have to pass a count of users on every method in that controller that displays a view, which is every single one! That isn’t very DRY!
Sometimes when creating a class others will use and extend, you may want to make sure some methods are not overridden. If it needs to be able to work with other APIs, making sure the interface of the class stays the same becomes very important. One way to do this is through the use of the final keyword in PHP.