2017 © Pedro Peláez
 

library concatenator

image

slovenian-gooner/concatenator

  • Wednesday, March 26, 2014
  • by slovenianGooner
  • Repository
  • 1 Watchers
  • 23 Stars
  • 86 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Concatenator for Laravel

A Laravel package that enables concantenation of database fields with Eloquent., (*1)

Warning

This package is still in beta testing, so bugs are expected, they always will be. If you find anything, just post an issue. If you have some ideas on how to upgrade it, feel free to post an issue aswell., (*2)

Compatibility

  • Laravel 4.0
  • Laravel 4.1

Installation

Add the package to your composer.json file..., (*3)

"require": {
    "slovenian-gooner/concatenator": "dev-master"
}

...and then run composer update and that should do it., (*4)

Usage

Include the Concatenator trait (example on User model)

Adding the Concatenator trait will overwrite the newBaseQueryBuilder() method to append the conactenated columns. Add the $concatenatedColumns property to the Eloquent model. It should be an array as seen in the example., (*5)

class User extends Eloquent
{
    use SlovenianGooner\Concatenator\ConcatenatorTrait;

    // Use this option to disable automatic appending to the select statement (defaults to true)
    // protected $autoAppendToSelect = false;

    protected $concatenatedColumns = array(
        'full_name' => ['first_name', ' ', 'last_name']
    );
}

The code above will append a full_name field to every query you make on this model. The resulting field appended will look like this:, (*6)

SELECT CONCAT(first_name, ' ', last_name) as full_name ...

If the $autoAppendToSelect option is set to false, then the only way to call a concatenated column is to specify it in the get function., (*7)

$user = User::first(['full_name']);

Order by

Order by method works independently without the need to append a concatencated column to the select statement ie. $autoAppendToSelect option can be set to false., (*8)

$user = User::orderBy('full_name')->first(); // This works even if the column is not in the select statement

This adds the following string to the order by statement:, (*9)

ORDER BY CONCAT(first_name, ' ', last_name) ...

Group by

Group by method works independently without the need to append a concatencated column to the select statement ie. $autoAppendToSelect option can be set to false., (*10)

$user = User::groupBy('full_name')->first(); // This works even if the column is not in the select statement

This adds the following string to the order by statement:, (*11)

GROUP BY CONCAT(first_name, ' ', last_name) ...

The Versions

26/03 2014

dev-master

9999999-dev

  Sources   Download

The Requires

  • php >=5.3.0

 

by Lovro Papež