sleeping-owl / admin

Administrative interface builder for Laravel
http://sleeping-owl.github.io/
MIT License
503 stars 259 forks source link

"unique" validation rule leads to QueryException (when editing) #266

Open NashGames opened 8 years ago

NashGames commented 8 years ago

Every time, I want to edit a model with a 'unique' validation rule, the following error shows:

QueryException in Connection.php line 651:
SQLSTATE[42S22]: Column not found: 1054 Unknown column '4' in 'where clause' (SQL: select count(*) as aggregate from `sports` where `4` = football)

For one of my models ("Sport") in table "sports", the validation rule looks like this:

private $rules = array(
        'name' => 'required|max:45',
        'slug' => 'required|max:45|unique:sports',
    );

My edit form contains the respective two fields:

Admin::model(Sport::class)->title('Sports')
->columns(function ()
{
    Column::string('name', 'name');
    Column::string('slug', 'Slug');
})->form(function ()
{
    FormItem::text('name', 'Name');
    FormItem::text('slug', 'Slug');
});

Furthermore, the model derives from 'SleepingOwl\Models\SleepingOwlModel' and getValidationRules() is set (it also works, when no "unique" field is set):

public function getValidationRules()
    {
        return $this->rules;
    }

Thanks for any help on that issue!