z-song / laravel-admin

Build a full-featured administrative interface in ten minutes
https://laravel-admin.org
MIT License
11.12k stars 2.81k forks source link

disableCreate() in Modal-show with one-to-many relationships not work #4830

Closed newnewcoder closed 4 years ago

newnewcoder commented 4 years ago

Description:

Hi, I created two models with one-to-many relationship. I tried to disable the create button in detail page as the following code but it does not work. Did i do something wrong?

Steps To Reproduce:

# in model
class MyModel extends Model
{
    protected $table = 'my_model';

    public function his()
    {
        return $this->hasMany('App\Models\MyModelHis', 'name', 'name');
    }
}

# in controller
protected function detail($id)
    {
        $show = new Show(MyModel::findOrFail($id));
        $show->panel()
            ->tools(function ($tools) {
                $tools->disableEdit();
                $tools->disableDelete();
            });;
        $show->field('id', __('ID'));
        $show->field('name', __('name'));
        $show->his(function ($his) {
            // --- not work
            $his->panel()->tools(function ($tools) {
                $tools->disableCreate();
            });
            // ---
            $his->id("ID");
            $his->tran_date('tran_date');
        });
        return $show;
    }
newnewcoder commented 4 years ago

thx!

$his is a Grid, so i should use $his->disableCreation(); instead of above.