Working with Laravel 4 or 5 and WordPress together

Hi everybody!

Updated Mar 3rd 2015: Are you using Laravel 5? Check these changes!

Updated May 11th 2014: Using Corcel project

Currently I am working on a project where I had to make some choices about technologies and how work with them together. First this project will be developed using WordPress only. It’s a College Group site, where we had to work with 13 schools around the world and each one must has the control of your own content.

This could be made with WordPress, but I think when the site is not so small maybe you can use another CMS or Framework, because I particularly prefer to work with MVC. So because some decisions inside the company we decided to use WordPress Admin Panel, that is a very good, use its architecture and its database. So WordPress will be used to the application back-end, with user control, user permission, etc.

To the front-end we decided to work with Laravel. To query information from the WordPress database we’ve used the WordPress functions inside Laravel, so it’s much better to work with a MVC WordPress.

Continue reading Working with Laravel 4 or 5 and WordPress together

Generating IDs like Youtube or Bit.ly using PHP

Let’s supose you want to develop your own URL shortener, like Bit.ly for example.

You can, of course, use the ID as a integer, like, 1, 2, 3, etc. If you have 12.345 rows in your database table, you will need 5 digits, like http://example.com/12345. Large applications like Youtube, have much more entries, so, to use numbers, the URL will be very long, like http://youtube.com/watch?v=231268318276783.

Because that, these websites, like YouTube, t.co, bitly.com or even vine.co, are using a generated ID using uppercase letters, lowercase letters, digits and sometimes underscore (_) and hyphen (-). You can check that given a YouTube video URL where you will find something like http://www.youtube.com/watch?v=2Z4m4lnjxkY. You can see they’re using the “2Z4m4lnjxkY” as ID.

Continue reading Generating IDs like Youtube or Bit.ly using PHP

Managing assets with Laravel 4

Generally assets are stored in your public directory, right? They are public, so anyone can get access to them. But nowadays the performance is a very important factor when deploying a new app. I strongly recommend you to minify and cache your assets, like CSS files, Javascript files and Images.

If you are using 11 javascript files in your app you don’t have to make 11 requests on the server, one per JS files. You can easily join all files and minify them, so you will have just one minified file. This is easy to do using Laravel 4! I’ve found four Laravel 4 assets managers:

We will work with codesleeve/asset-pipeline package. It’s easy to use and simple to understand.

Continue reading Managing assets with Laravel 4

Working with PHP 5.4+ built-in server with Laravel 4

One of the best improvements of the PHP 5.4 was the built-in web server. Like in Ruby On Rails, now you do not need Apache or Nginx inside your development machine.

To start a web server is easy:

php -S localhost:8000

Continue reading Working with PHP 5.4+ built-in server with Laravel 4

Be a better PHP developer

Actually this post is a outflow and at the same time an advice. I have seen some PHP developers that are completely OUT of what is happening in the PHP world, besides committing some mistakes that cannot be accepted.

PHP 5.3+

If you are entitled as a PHP developer you must to update. In my opinion the best improvements of the language after version 5.3 were namespaces and closures. If you don’t know about it, UPDATE yourself, because these added functionalities allowed a fast growth of the language, and developers that are not using them are lagging behind.

Continue reading Be a better PHP developer

Solve the problem. Just it!

These days I’m thinking about productivity and the use of PHP frameworks. I’ve read some posts about framework X or Y, defending a framework instead of another one.

I know people that use a framework like Zend Framework to develop a simple website just to say they’re using it, and not an “easy” framework. I think you must to solve the problem, not create another one. You have to use best practices but first you have to solve the problem, nothing more.

You don’t have to use a hard-to-learn framework just to say your friends you know about it. You can do amazing things with easy-to-learn frameworks, like Code Igniter, CakePHP, Laravel or Slim. You can do better even with pure PHP if you want, but you have to concern about productivity (and security of course).

Continue reading Solve the problem. Just it!

Design Patterns with PHP – Adapters

Hi all!

Today I am starting a post series about Design Patterns. I have wrote about them a lot but only suggesting you to learn about to be a better developer. I am studying them, so nothing better to write about and improve my knowledges too.

I only ask you to read everything to understand the concepts behind the patterns. You have to understand them to know where you can use one or another.

Continue reading Design Patterns with PHP – Adapters

Testing your Packagist/Composer package locally

Hello again! It’s my second post today! I’m electric!

I am developing a project that uses a package I’m developing too. So, it is a real time test project. I find a new way to do something and write it inside my package and uses that.

But sometimes this is a boring work. I am sharing my package in the Packagist website using Composer, and everything I change I have to commit, push to GitHub and update my project with Composer, to get the new code I’ve wrote. That’s a very very bad idea.

Yesterday I was talking with my friend @diegoholiveira about to test the package locally and we’ve found a easy solution. You can change the package you are developing and use that in the project that uses it. We were trying to find an easy way to do that using Composer, but the solution was easier than that. Just use symbolic links.

Continue reading Testing your Packagist/Composer package locally

Contributing with the PHP community

Hi guys!

Everyone wants to contribute in some way with developers. Maybe you’re thinking in a project to develop and share but you search at Google and find someone who already did that.

Maybe the answer to this problem is in front of you. Everything you do can be reused in a future project. If you’re working in a project in the company you works, I’m sure you have some piece of code that you had to thought to develop it. So you can contribute.

I am now developing the WordPress Corcel, that is a small set of classes that works in a WordPress database, retrieving data and working with them. It uses the Eloquent ORM, developed for the Laravel Framework.

This project is the result of a project we’re developing inside my advertising company. We had to integrate some libraries and databases with a WordPress installation but WordPress was too closed to do that, so we started to work in some classes that with Composer we’ll can use in that project, using Slim Framework or another framework that uses Composer too.

Continue reading Contributing with the PHP community

Creating your first Composer/Packagist package

Hi everybody! Today I’ll write about how you can contribute with PHP community creating packages (or updating your’s) using Composer and Packagist. First, if you’re a PHP developer and don’t know yet what is Composer, take a look on the post Why you should use Composer and how to start using it to get more information about.

Using Composer

Composer is a package manager for PHP. You can use packages the community developed and you can contribute with your packages too. Here I’ll show how to create a project/package, install Composer inside it and send to Packagist, where others developers can use it inside their projects.

Continue reading Creating your first Composer/Packagist package