Editing after saving doesn't show selected input

Viewed 422

I'm using the Backpack for Laravel CRUD features & currently having an issue with the select field type as to which after saving the form, once I go back to try and edit it isn't pre-defining my selected option?

Here's my setup() code inside my Accounts controller:

$this->crud->setModel("App\Models\Accounts");
$this->crud->setRoute("admin/accounts");
$this->crud->setEntityNameStrings('Accounts', 'Account');

$this->crud->addField([
    'label' => "Proxy",
    'type' => 'select',
    'name' => 'proxy_id',
    'entity' => 'proxy',
    'attribute' => 'id',
    'model' => "App\Models\Proxies",
    'nullable' => true
]);

And here's my proxy() entity within the Accounts model:

public function proxy()
{
    return $this->hasOne(Proxies::class, 'id', 'proxy_id');
}

Here's the App\Models\Proxies class:

class Proxies extends Model
{

    use CrudTrait;

    public $timestamps = false;

    protected $table = 'proxies';

    protected $fillable = [
        'ip',
        'port',
        'username',
        'password',
        'status'
    ];

    public function getStatusValue()
    {
        switch($this->status) {
            case "0":
                return '<span class="label label-success">Offline</span>';
                break;
            case "1":
                return '<span class="label label-success">Online</span>';
                break;
        }
        return null;
    }

}

Here's my DB migration for the proxy_id column:

public function up()
{
    Schema::table('accounts', function(Blueprint $table)
    {
        $table->integer('proxy_id')->nullable();
    });
}

UPDATE I have added {!! $field['name'].' - '.old($field['name']).' - '.$connected_entity_entry->getKey() !!} to a newly created file: /resources/views/vendor/backpack/crud/fields/select.blade.php and the result I'm seeing is:

proxy_id -  - 1

So it appears the old() function isn't working correctly?

0 Answers
Related