Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

cewlbird's avatar

Auth Facade breaking views in PHP 7.1.7?

Dear community,

I noticed some strange behaviour in my application (Laravel 5.4.33).

As soon as I use the following snippets within my views (any kind of Auth:: combination) it breaks my code at this part of the code, but I don't get any errors

<li class="dropdown messages-menu">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown">
        <i class="fa fa-bell"></i>
        <span class="label {{ Auth::check() && Auth::user()->unreadNotifications->count() > 0 ? 'label-danger' : 'label-success' }} notification_count">{{ Auth::user()->unreadNotifications->count() }} </span>
    </a>
    <ul class="dropdown-menu">
        <li class="header notification_count">You have {{ Auth::check() && Auth::user()->unreadNotifications->count() }} notification(s)</li>
        <li>
            <!-- inner menu: contains the actual data -->
            <ul class="menu notification-items">
                @include('backend.pages.notification.partials.notification-item')
            </ul>
        </li>
        <li class="footer"><a href="{{ route('backend.notification.index') }}">See All Notifications</a></li>
    </ul>
</li>

alt text

Is there any known bug with PHP 7.1.7 and laravel or am I missing something else here? The code works perfectly with PHP 7.0.

When I remove this portion of code, it works until the next auth:: code appears.

Best Regards

0 likes
9 replies
cewlbird's avatar

Hi @snapey,

see my screenshot above, the complete html output just breaks at the red line you see above.

The page stops rendering the html output. I don't get any errors unfortunately it just stops rendering at the point where I use anything like Auth::.

So the page is just broken as it doesnt load the rest of my page. As soon as I switch to PHP 7.0 it just renders fine.

JackJones's avatar

I know it doesn't answer your question, but out of general interest does

@if(Auth::check() && Auth::user()->unreadNotifications->count()) label-danger @else label-success @endif

Work?

Snapey's avatar

usually a halt in the code like this, with no error reported is a sign of an out of memory issue.

The suspect would be the ->count() method. Test the function separately in Tinker ?

Also check how much memory you have available in 7.0 versus 7.1

Jaytee's avatar

Let's clean that view up anyway. If the user isn't logged in, then they shouldn't even have a notifications dropdown.

So, wrap all of that dropdown between an if statement to check whether a user is signed in. Then you don't need to check whether they're authenticated for the classes etc.

cewlbird's avatar

Hi,

thank your for your replies so far:

@JackJones Unfortunately this doesn't work, the code still breaks.

@Snapey PHP 7.0 has configured 128mb and 7.1 has even 512mb configured in my php.ini, so it shouldn't be a memory issue as it seems. Also I don't have any notifications in my database, so count returns 0 at the moment.

@Jaytee This doesn't help either, anything like Auth::check oder Auth::user still breaks the code.

I am quite clueless why this is happening, it never happended before with PHP 7.0 and switching back to this version isn't an option for me :(

cewlbird's avatar

Hi,

I think I found the problem, it seems the xdebug settings are making trouble:

xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.remote_handler = dbgp

xdebug.profiler_enable = 0;
xdebug.profiler_output_dir = "~/Desktop";
xdebug.profiler_output_name = xdebug.out.%t
xdebug.show_local_vars=1

xdebug.idekey=PHPSTORM

xdebug.auto_trace = 1
xdebug.collect_includes = 1
xdebug.collect_params = 1
xdebug.collect_return = 1
xdebug.extended_info = 1
xdebug.max_nesting_level = 100
xdebug.var_display_max_children = 128

As soon as I remove the bottom part and restart apache, it just works fine.

Thank you guys for your support, seems like the puzzle is solved, maybe memory was indeed an issue with these settings? @Snapey

Snapey's avatar

I would be worried that there is some recursion happening somewhere. You say it works now. Is the performance and number of DB queries as expected?

cewlbird's avatar

Hi @Snapey,

everything seems normal so far. I have about 7-8 queries inside my dashboard view.

At the most I have about 17 queries in a meal listing view, but I have to optimize it later on.

Isn't profiling and collecting params on every request via xdebug resource hungry? My app works now much faster after I removed the code snippet above.

Do you mean there could be some more problems in my app causing this to happen with xdebug?

Please or to participate in this conversation.