FrozenNode / Laravel-Administrator

An administrative interface package for Laravel
http://administrator.frozennode.com/
MIT License
1.94k stars 502 forks source link

Filter by Relation, returns 0 records #792

Closed catfishseo closed 9 years ago

catfishseo commented 9 years ago

I am trying to filter by the relationship and It return 0 records. What I am doing wrong? Everything else works fine (it displays all of the records with the right property name and filter drop-down box is generated correctly) Thank you,

This is the PropertyList model

<?php
class PropertyList extends Eloquent {
    protected $table = 'property_list';

    protected $guarded = [
        "id",
        "created_at",
        "updated_at"
    ];

}

This is the PropertyImage model

<?php
class PropertyImage extends Eloquent {
    protected $table = 'property_image';

    protected $guarded = [
        "id",
        "created_at",
        "updated_at"
    ];

    public function property()
    {
        return $this->belongsTo('PropertyList','property_list_key','key');
    }
}

My propertyimages model conf

return array(

    'title' => 'Apartment Images',
    'single' => 'apartment',
    'model' => 'PropertyImage',

    'columns' => array(
        'property' => array(
            'title' => 'Property',
            'relationship' => 'property',
            'select' => '(:table).name',
        ),
    ),

    'edit_fields' => array(
        'property' => array(
            'title' => 'Property',
            'type' => 'relationship',
            'name_field' => 'name',
        ),
    ),

    'filters' => array(
        'property' => array(
            'title' => 'Property',
            'type' => 'relationship',
            'name_field' => 'name',
        ),
    ),

);
davemathews commented 9 years ago
        return $this->belongsTo('PropertyList');

and make sure PropertyList has a name column.