Nobodys Fault

“It’s Nobodys Fault but Mine”: Blind Willie Johnson (1927). Covered by JJ Appleton, Tim Lefebvre (Bass) from the Derek Trucks Band and Jason Ricci 2nd Position (Cross harp Key of G on a C harp). From a live video and audio recording session in Manhattan NYC, circa: Oct. 2014.live to film recording of “Just Enough” written by JJ Appleton.

Laravel : Query Scopes, Accessors and Mutators

Query Scopes

Query scopes are easier way to re-use logic in your model than writing where clauses all over again and again for the same logic.

We will use a user model which has a property “active” a boolean value.

User
    -id [1]
    -username [john]
    -firstname [john]
    -lastname  [doe]
    -password [hashedpassword]
    -active [1]

We need to query for all users who are active (active = 1). To use scopes we prefix the function name with “scope”. Below is example for querying for active users.

class User extends Eloquent {

    public function scopeActive($query){
        return $query->where('active' , '=', 1);
    }
}

You can retrieve the active users as below. Also, you can use multiple scopes on a model.

$users = User::active()->get();

/*multiple scopes - active users - male users 
assuming that scopeMale function is added to the model */

$male_users = User::active()->male()->get();

Mutators

Mutuators can be utitlised to manipulate the data before saving into the database. One of the place where I use mutators are for passwords. Lets consider the same user model, when creating/updating or seeding a user you have to hash the password. So you would do something like

$user->password = Hash::make('password');

Since password has to be hashed everytime before saving into the database it would be nice if we could do it one place and just before saving. We can achieve this using mutators.

class User extends Eloquent {

    public function setPasswordAttribute($value) {
        $this->attributes['password'] = Hash::make($value);        
    }
}

Accessors

Accessors are opposite to mutators, it lets us to manipuldate the data just before returning the data on query. For example, we want to capitalize the first letter in the first name everytime. I am just going to write the function since it is understood that it is inside the user model.

public function getFirstNameAttribute($value){
    return ucfirst($value);
}

We can also use this to get custom property on the model. For example, a property on the user model “full_name” which would concatenate first name and last name. Notice that this would return first name with first letter capitalized since we did that in the previous accessor method.

public function getFullNameAttribute($value){
    return $this->first_name . " " . $this->last_name;
}

$user = User::find(1);
$user->full_name;
//John doe

 

source: http://www.ashwinsureshkumar.com/laravel-query-scopes-accessors-and-mutators/

Great Digital Products Don’t Happen By Accident.

The right team — Multi-disciplinary, constrained in size, experienced, mutual learning mindset, given focus.
Real problems for real people — Validate the problems we are working on vs. solving made-up problems for imaginary personas or hypothetical addressable markets.
Measurable outcomes — Precise, clear, unambiguous goals to help us focus, make decisions, and optimize over time.
Make decisions through use — Usage is like oxygen for ideas, so get out of Photoshop or Sketch and validate design direction by making something and using it; let what you’ve built serve as a vantage point to see where to go next.
Iterate and refactor — No sacred cows, no commitments to cleverness or pet ideas or sunk costs. Making something new is not a linear process. If something isn’t working, tear it down and build something that does.
Seamless UX — The best experiences are seamless. They promote flow across sessions, devices and use cases. If we’re constantly focusing-in, we also have to build in times where we pause, zoom-out, and reconcile everything to the larger picture of what we’re making.

 

source: https://medium.com/@davegillis/great-digital-products-dont-happen-by-accident-b3833a82da22