Filtering Arrays In Javascript

By Michael Williams, Published on 04/26/2018

Using the filter() method is a quick way to take all of the items from one array that match a criteria and move them to another.

In this example. Lets assume that we have an array of cars and only want to display those which are black.

const cars = [ { id: 1, make: 'BMW', model: 'Alpina B7', color: 'Black' }, { id: 2, make: 'BMW', model: 'i8', color: 'White' }, { id: 3, make: 'Tesla', model: 'Model X', color: 'Blue' }, { id: 4, make: 'Honda', model: 'Civic', color: 'Black' } ]; const blackCars = cars.filter(car => car.color === 'Black');

If we were to console.log() the results. We would be left with:

Dynamic Where Clauses in Laravel Eloquent

By Michael Williams, Published on 04/24/2018

One of the many features that doesn't appear to be widely discussed regarding Eloquent, is the ability to use dynamic information in the where clauses.

Assuming that you have a Users model and want to retrieve a result based on email. It's known that you can query the database as such:

return $this->users->where('email', '[email protected]')->first();

Did you know that you could also write the query as:

return $this->users->whereEmail('[email protected]')->first();

You can even add multiple fields:

Accessors and Mutators in Laravel

By Michael Williams, Published on 04/23/2018

In Laravel, Accessors and Mutators allow you to format attributes when they are retrieved or when they are set on your models.

The beauty in Accessors and Mutators is that, once defined. The behavior you specify, will always be associated with those fields.

Defining An Accessor:

Lets assume that you have a Users model with a last_visit_date column. You would create the following method studly cased.

public function getLastVisitDatetAttribute($date) { return Carbon::createFromFormat('Y-m-d H:i:s', $date)... }
PHP variable name conventions

By Michael Williams, Published on 10/21/2016

Whenever someone is new and asks any advice about where to start on their path to learning PHP. In addition to the documentation. Two places I usually recommend are: PHPTheRightWay and PHP-FIG.

With front end frameworks today, such as bootstrap. It's a lot easier to get going with a decent looking site. Unfortunately a clean front-end, does not automatically translate to clean back-end.

When working with a lot of 3rd party software. Efficiency will be left out for this topic. I want to focus solely on variable names and readability.

Lets look at two code samples

Time saving shortcuts in PhpStorm

By Michael Williams, Published on 10/20/2016

PHPStorm has been my IDE of choice for some time now. That said, there are still new shortcuts I'm either learning or implementing into my workflow all the time. 

Here are some of my favorites:

1 2 3 4