relationExtendManageWidget

by Michael Dibbets

JavaScript

public function relationExtendManageWidget($widget, $field)
    {
        switch($field) {
            case 'items':
                if($widget instanceof Lists) {
                    $widget->addFilter(function($query) {
                        return $query->doesntHave('vehicle');
                    });
                }
                break;
            case 'bank_transactions':
                if($widget instanceof Backend\Widgets\Form)  {
                    $formController = $widget->getController()->asExtension('FormController');
                    if($formController->formGetContext() !== 'update') return;

                    dd($formController->formGetModel()->getAttributes());
                }
                break;
            default:
                break;
        }
    }

public function relationExtendManageWidget($widget, $field)
    {
        switch ($field) {
            case 'items':
                if ($widget instanceof Lists) {
                    $widget->addFilter(function ($query) {
                        return $query->doesntHave('vehicle');
                    });
                }
                break;

            case 'bank_transactions':
                if ($widget instanceof Backend\Widgets\Form) {
                    $invoiceFormWidget = $widget->getController()->widget->form;
                    if ($invoiceFormWidget->getContext() !== 'update') return;

                    $invoice = $invoiceFormWidget->model;

                    $widget->model->amount = $invoice->total;
                    $widget->model->customer_type = $invoice->customer_type;
                    $widget->model->company = $invoice->company;
                    $widget->model->person = $invoice->person;
                }
                break;

            default:
                break;
        }
    }