Closed ziming closed 9 years ago
What error do you get? Any other relevant information?
@bobbybouwmann it will say Seeded:... in console but in reality nothing got seed for that table. laravel.log has nothing too.
I just tried with a new model, it doesn't work too unless I use Eloquence and Mutable traits instead of extends Sofa\Eloquence\Model and use Mutable trait. When I look at the source code Sofa\Eloquence\Model uses Eloquence trait hence that makes it confusing for me.
User model is the only exception so far.
You don't exstend the LetterType
class with Eloquence, I think the issue is there
This:
use Illuminate\Database\Eloquent\Model;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Mutable;
class LetterType extends Model {
Should be this:
use Sofa\Eloquence\Model;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Mutable;
class LetterType extends Model {
Hi @bobbybouwmann in my example, seeding fails when I extends Sofa\Eloquence\Model. but it works when I extends Illuminate\Database\Eloquent\Model and use the validable traits and interface instead.
Hi further investigation shows to me that it is Validable that's causing the problem.
I tested this by creating an AppModel abstract class and extends it from my other models.
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Sofa\Eloquence\Contracts\CleansAttributes;
use Sofa\Eloquence\Contracts\Validable as ValidableContract;
use Sofa\Eloquence\Eloquence;
use Sofa\Eloquence\Mappable;
use Sofa\Eloquence\Mutable;
use Sofa\Eloquence\Validable;
abstract class AppModel extends Model implements ValidableContract, CleansAttributes
{
use Eloquence, Mutable, Mappable, Validable;
}
When I remove ValidableContract, CleansAttributes and Validable, from the super class then it works.
I don't think it is an issue with my validation rules if any because when my concrete classes implements ValidableContract, CleansAttributes and use the Validable trait, seeding works fine. It just fails if these are in my superclass instead.
@ziming @bobbybouwmann I'm on holiday, I will take a look at this in a few days. If you can do it sooner, then pls do. Thanks
@jarektkaczyk I don't have much time this week, so I can't take a look at it for now. I bet you will be back sooner then I am ;)
Update, I notice problems again this time when I use middleware. Got to implement the contracts and traits in the class itself instead of extending the super class for it to work again. Hope it helps!.
@ziming I've tested that on L5.0 and nothing bad happens. Seeding works as expected, so if the problem persists, please upload whole code so I can see it.
I am using laravel 5.1 and mostbof the time the issue happen when using it with laravel administrator. I'm outside now so I can't test it right now. Sometimes the problem is solved by running php artisan optimize. Sometimes isn't. Thank you.
When my model code is this, seeding doesn't work
Seeding only works when I change to:
This is strange to me because for my User model, extending Sofa\Eloquence\Model gives me no issue in seeding. But for my LetterType model, it does.