skip to Main Content

I have several purchasable models that have a many to many relation ship with the customer model. As such I am using a BelongsToMany relationship.

 BelongsToMany::make(__('Courses'), 'courses', Course::class)
                ->sortable()
                ->searchable(),

To ensure a sepeate checkout process cannot be bypassed, I need to disable the attach action of the relationship:

Attach Course Image

How can I prevent the course from being attached to the user?

2

Answers


  1. BelongsToMany::make(__('Courses'), 'courses', Course::class)
    ->sortable()
    ->searchable()
    ->disableAttaching(),
    

    try doing this

    Login or Signup to reply.
  2. public function authorizedToAttachAny(NovaRequest $request, $model)
        {
          return false;
        }
    
    

    Override this method in the nova resource.

    Also, found this in official documentation, if you want to try out
    https://nova.laravel.com/docs/resources/authorization.html#authorizing-attaching-detaching

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search