public function attachToModel(Model $model, $type = '', $locale = null): Model
    {
        if ($model->assets()->get()->contains($this)) {
            throw AssetUploadException::create();
        }

        $model->assets->where('pivot.type', $type)->where('pivot.locale', $locale);

        $locale = $locale ?? config('app.locale');

        $model->assets()->attach($this, ['type' => $type, 'locale' => $locale, 'order' => $this->order]);

        return $model->load('assets');
    }
public function attachToModel(Model $model, $type = '', $locale = null): Model
    {
        if ($model->assets()->get()->contains($this)) {
            throw AssetUploadException::create();
        }

        $model->assets->where('pivot.type', $type)->where('pivot.locale', $locale);

        $locale = $locale ?? config('app.locale');

        $model->assets()->attach($this, ['type' => $type, 'locale' => $locale, 'order' => $this->order]);

        return $model->load('assets');
    }
public function attachToModel ( Model $ model , $ type = '' , $ locale = null ) : Model { if ( $ model -> assets ( ) -> get ( ) -> contains ( $ this ) ) { throw AssetUploadException :: create ( ) ; } $ model -> assets -> where ( 'pivot.type' , $ type ) -> where ( 'pivot.locale' , $ locale ) ; $ locale = $ locale ?? config ( 'app.locale' ) ; $ model -> assets ( ) -> attach ( $ this , [ 'type' => $ type , 'locale' => $ locale , 'order' => $ this -> order ] ) ; return $ model -> load ( 'assets' ) ; }
Attaches this asset instance to the given model and
sets the type and locale to the given values and
returns the model with the asset relationship.

@param Model $model
@param string $type
@param null|string $locale
@return Model
@throws \Thinktomorrow\AssetLibrary\Exceptions\AssetUploadException
Attaches this asset instance to the given model and sets the type and locale to the given values and returns the model with the asset relationship .