2

I am using laravel 4 and I want to keep track of history of all transactions made to a table. I followed those steps

  1. added "venturecraft/revisionable": "1.*" at composer.json
  2. php composer.phar update
  3. run in the root of my project this :

    php artisan migrate --package=venturecraft/revisionable

and it says "nothing to migrate"

then i copied the migration file from the package in my app/database folder, and changed the classname from CreateRevisionsTable to something like CreateRevisionTable and the table was created in my database. Then I added this in my Car model:

1.

 class Car extends Eloquent {
    use \Venturecraft\Revisionable\RevisionableTrait;

    protected $keepRevisionOf = array(
    'Description'
    );

}

Then in my controller:

 $description = Car::find($id);
        $history = $description->revisionHistory;

And then in my view:

 @foreach($history->revisionHistory as $h )
                <li>{{ $h->userResponsible()->username }} changed {{ $h->fieldName() }} from {{ $h->oldValue() }} to {{ $h->newValue() }}</li>
                @endforeach

composer.json

"require": {
        "laravel/framework": "4.1.*",
        "ajessup/gae-laravel": "dev-master",
                "venturecraft/revisionable": "1.*"
    },

And the result is:

Trait 'Venturecraft\Revisionable\RevisionableTrait' not found 

What am I missing?

menjaraz
  • 7,551
  • 4
  • 41
  • 81
  • Go to the source of the library you added. See if that trait in actually there. If it is not, try my answer. – Flosculus May 15 '14 at 08:33

2 Answers2

2

Try setting the item in composer to:

"venturecraft/revisionable": "~1.8"

This will match any version from 1.8 to but not including 2.0.

EDIT: This solution makes no difference.

EDIT: Maybe.

Flosculus
  • 6,880
  • 3
  • 18
  • 42
  • ok i am missing something, should I copy and paste the package venturecraft in my project root or just include "venturecraft/revisionable": "1.*" and run composer update? Because in the folder that I downloaded it has 4 files "FieldFormatter", "RevisionableTrait", "Revisionable", "Revision" BUT THIS FILES AREN'T IN MY PROJECT EVEN AFTER composer update and dump-autoload –  May 15 '14 at 08:38
  • tried "venturecraft/revisionable": "~1.8" and the same –  May 15 '14 at 08:40
  • I was wrong. I ran `composer require venturecraft/revisionable 1.*` in an empty directory and it gave me `1.8` which had the trait. However, when I created a class with that trait, there were no errors. – Flosculus May 15 '14 at 08:43
  • explain me something pls. After download the packages. should I include them in my project? or just add "venturecraft/revisionable": "1.*" in composer.json of my project and then at the root of my project run : composer.phar update? I am not copying and paste the package that downloaded and there are not in my project –  May 15 '14 at 08:45
  • With composer you don't need to download the packages to add them manually. When you use composer, the vendor/autoload.php file needs to be included, then all classes in the vendors are exposed. I am assuming Laravel does this for you. – Flosculus May 15 '14 at 08:47
  • well now it is updated with theing v command you gave me composer require venturecraft/revisionable 1.* But it is saying Undefined variable: history. What am i doing wrong now? –  May 15 '14 at 09:02
  • Well it looks like your problem is solved, odds are even though you added the library to your project, the classes weren't loaded. This new error is unrelated, simple a bug you should be able to solve. – Flosculus May 15 '14 at 09:05
  • well thank you :) if you could help me with the steps how to call $car = Car::find($id); $history = $car->revisionHistory; in my controller or model ?? –  May 15 '14 at 09:11
  • it shows this in view Undefined property: Illuminate\Database\Eloquent\Collection::$revisionHistory –  May 15 '14 at 09:13
  • I'm afraid I am not familiar with Laravel. You may want to re-tag your question as `php traits composer`, then ask another question related to MVC with Laravel. – Flosculus May 15 '14 at 09:14
0

Just run composer dumpautoload and it should work...

Sasa Tokic
  • 201
  • 2
  • 4