brexis / laravel-workflow

Use the Symfony Workflow component in Laravel
MIT License
281 stars 105 forks source link

Simple Sample please #9

Closed jfpwork closed 6 years ago

brexis commented 6 years ago

Hi @jfpwork, did you try this https://github.com/brexis/laravel-workflow#usage ?

brexis commented 6 years ago

What version of Laravel are you using? I think you may forget the Workflow alias configuration in your Laravel project. https://github.com/brexis/laravel-workflow#installation

jfpwork commented 6 years ago

First thanks. Version 5.4 got exception when $post->save(); ( Array to string conversion (SQL: update blog_posts set currentPlace = 1, updated_at = 2017-12-11 15:28:53 where id = 1) )

boneq commented 6 years ago

@jfpwork My problem is the same as yours.

MyDigitalLife commented 6 years ago

You can fix this by using mutators: https://laravel.com/docs/5.5/eloquent-mutators So my model would look like this:

class BlogPost extends Model
{
    use WorkflowTrait;

    public function setCurrentPlaceAttribute($value)
    {
        $this->attributes['currentPlace'] = json_encode($value);
    }

    public function getCurrentPlaceAttribute()
    {
        return json_decode($this->attributes['currentPlace'], true);
    }
}
brexis commented 6 years ago

I'm closing this issue as it's not related to laravel-workflow but to laravel.

qerim commented 5 years ago

You can fix this by using mutators: https://laravel.com/docs/5.5/eloquent-mutators So my model would look like this:

class BlogPost extends Model
{
    use WorkflowTrait;

    public function setCurrentPlaceAttribute($value)
    {
        $this->attributes['currentPlace'] = json_encode($value);
    }

    public function getCurrentPlaceAttribute()
    {
        return json_decode($this->attributes['currentPlace'], true);
    }
}

Or you could simply write it as:

class BlogPost extends Model
{
    use WorkflowTrait;

    protected $casts = [
        'currentPlace' => 'json'
    ];
}