ViralTiger of Viralbamboo Application Developers
9/28/2017 - 2:14 PM

Check if MANY-MANY relationship existence & execute function if TRUE

        /**
         * Check if MANY-MANY relationship existence & execute function if TRUE
         * @var [type]
         */
        if (is_null(Auth::user()->model->where('id', $model->id)->first())) {
        
            Auth::user()->models()->attach(
                $model->id,
               ['created_at' => date('Y-m-d H:i:s')]
            );
            
        }