Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hooking into model events causes no slug to be created #34

Closed
prateem opened this issue Jun 13, 2014 · 3 comments
Closed

Hooking into model events causes no slug to be created #34

prateem opened this issue Jun 13, 2014 · 3 comments

Comments

@prateem
Copy link

prateem commented Jun 13, 2014

In controller:

$input = Input::all();
$this->model->fill($input)->save()

In model:

public static function boot() {
    parent::boot();
    static::saving(function($model) {
        return $model->arbitraryFunction();
    });
}

When I try to use this method, no slug is generated. Specifically, the return causes the failure. Confirmed by commenting like so:

In model:

public static function boot() {
    parent::boot();

    static::saving(function($model) {
        // return $model->arbitraryFunction();
    });
}

This causes the slugs to be generated again.

@prateem
Copy link
Author

prateem commented Jun 13, 2014

Perhaps this may be important: Let's say my model relationships are as follows:

<?php
class Fruit extends Eloquent {
    public function boot() {
        parent::boot();
        static::saving(function($model) {
            return $model->arbitraryFunction();
        });
    }

    public function arbitraryFunction() {
        // do stuff
    }

    // ....
}
?>

And the model which has the sluggable behaviour:

<?php
use Cviebrock\EloquentSluggable\SluggableInterface;
use Cviebrock\EloquentSluggable\SluggableTrait;

class Orange extends Fruit implements SluggableInterface {
    use SluggableTrait;
    protected $sluggable = [
        'build_from' => 'name',
        'save_to' => 'slug'
    ];

    // .....
}

Edit: Whoops, didn't mean to close the issue.

@prateem prateem closed this as completed Jun 13, 2014
@prateem prateem reopened this Jun 13, 2014
@prateem prateem closed this as completed Jun 13, 2014
@prateem
Copy link
Author

prateem commented Jun 13, 2014

Okay the obvious fix was to only return the false if the function returned false.

@cviebrock
Copy link
Owner

Glad you figured this all out without me. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants