Skip to content

Commit

Permalink
fix illuminate 5.2 version
Browse files Browse the repository at this point in the history
  • Loading branch information
jarektkaczyk committed Jan 14, 2016
1 parent 0599a88 commit ae87508
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Sofa/Hookable

[![Build Status](https://travis-ci.org/jarektkaczyk/hookable.svg)](https://travis-ci.org/jarektkaczyk/hookable) [![stable](https://poser.pugx.org/sofa/hookable/v/stable.svg)](https://packagist.org/packages/sofa/hookable)
[![Build Status](https://travis-ci.org/jarektkaczyk/hookable.svg)](https://travis-ci.org/jarektkaczyk/hookable) [![stable](https://poser.pugx.org/sofa/hookable/v/stable.svg)](https://packagist.org/packages/sofa/hookable) [![Downloads](https://poser.pugx.org/sofa/hookable/downloads)](https://packagist.org/packages/sofa/hookable)

Hooks system for the Eloquent ORM (Laravel 5.1+ LTS).
Hooks system for the [Eloquent ORM (Laravel 5.2)](https://laravel.com/docs/5.2/eloquent).

Hooks are available for the following methods:

Expand All @@ -11,6 +11,7 @@ Hooks are available for the following methods:
* `Model::save`
* `Model::toArray`
* `Model::replicate`
* `Model::isDirty`
* `Model::__isset`
* `Model::__unset`

Expand All @@ -21,15 +22,13 @@ and all methods available on the `Illuminate\Database\Eloquent\Builder` class.
Clone the repo or pull as composer dependency:

```
composer require sofa/hookable:~1.0
composer require sofa/hookable:~5.2
```

## Usage

In order to register a hook you use static method `hook` on the model: [example](https://github.com/jarektkaczyk/eloquence/blob/5.1/src/Mappable.php#L42-L56).

To remove all hooks from a model use the static method `flushHooks`.

**Important** Due to the fact that PHP will not let you bind a `Closure` to your model's instance if it is created **in a static context** (for example model's `boot` method), you need to hack it a little bit, in that the closure is created in an object context.

For example see the above example along with the [class that encloses our closures in an instance scope](https://github.com/jarektkaczyk/eloquence/blob/5.1/src/Mappable/Hooks.php) that is being used there.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
}
],
"require": {
"php": ">=5.5.9"
"php": ">=5.5.9",
"illuminate/database": "5.2.*"
},
"require-dev": {
"crysalead/kahlan": "~1.1"
Expand Down
11 changes: 6 additions & 5 deletions src/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,15 @@ public function oldest($column = 'created_at')
}

/**
* Get a single column's value from the first result of a query.
* Get an array with the values of a given column.
*
* @param string $column
* @return mixed
* @param string|null $key
* @return array
*/
public function pluck($column)
public function pluck($column, $key = null)
{
return $this->value($column);
return $this->callHook(__FUNCTION__, $this->packArgs(compact('column', 'key')));
}

/**
Expand Down Expand Up @@ -534,7 +535,7 @@ public function count($columns = '*')
*/
public function lists($column, $key = null)
{
return $this->callHook(__FUNCTION__, $this->packArgs(compact('column', 'key')));
return $this->pluck($column, $key);
}

/**
Expand Down

0 comments on commit ae87508

Please sign in to comment.