public function hideFieldsByPolicy($fix, $fix_is_prefix = true, $delimiter = '.', $fields = null, $user = null)
    {
        if (!$fields) {
            $fields = $columns = Schema::getColumnListing($this->getTable());
        }

        if (!$user) {
            $user = \Auth::user();
        }

        $current_hidden = $this->getHidden();
        foreach ($fields as $field) {
            // Apply the prefix/suffix
            $field_ability = ($fix_is_prefix) ? $fix.$delimiter.$field : $field.$delimiter.$fix;
            // if field is not hidden currently hidden and the user can not access it then add to hidden fields
            if (array_search($field, $current_hidden) === false
                && $user->cannot($field_ability, app(Request::class))) {
                array_push($current_hidden, $field);
            }
        }

        $this->setHidden($current_hidden);

        return $this;
    }
public function hideFieldsByPolicy($fix, $fix_is_prefix = true, $delimiter = '.', $fields = null, $user = null)
    {
        if (!$fields) {
            $fields = $columns = Schema::getColumnListing($this->getTable());
        }

        if (!$user) {
            $user = \Auth::user();
        }

        $current_hidden = $this->getHidden();
        foreach ($fields as $field) {
            // Apply the prefix/suffix
            $field_ability = ($fix_is_prefix) ? $fix.$delimiter.$field : $field.$delimiter.$fix;
            // if field is not hidden currently hidden and the user can not access it then add to hidden fields
            if (array_search($field, $current_hidden) === false
                && $user->cannot($field_ability, app(Request::class))) {
                array_push($current_hidden, $field);
            }
        }

        $this->setHidden($current_hidden);

        return $this;
    }
public function hideFieldsByPolicy ( $ fix , $ fix_is_prefix = true , $ delimiter = '.' , $ fields = null , $ user = null ) { if ( ! $ fields ) { $ fields = $ columns = Schema :: getColumnListing ( $ this -> getTable ( ) ) ; } if ( ! $ user ) { $ user = \ Auth :: user ( ) ; } $ current_hidden = $ this -> getHidden ( ) ; foreach ( $ fields as $ field ) { // Apply the prefix/suffix $ field_ability = ( $ fix_is_prefix ) ? $ fix . $ delimiter . $ field : $ field . $ delimiter . $ fix ; // if field is not hidden currently hidden and the user can not access it then add to hidden fields if ( array_search ( $ field , $ current_hidden ) === false && $ user -> cannot ( $ field_ability , app ( Request :: class ) ) ) { array_push ( $ current_hidden , $ field ) ; } } $ this -> setHidden ( $ current_hidden ) ; return $ this ; }
Add not authorized fields for a user to model hidden fields.

@param $fix
@param bool   $fix_is_prefix
@param string $delimiter
@param null   $fields
@param null   $user

@return $this
Add not authorized fields for a user to model hidden fields .