jeudi 5 octobre 2017

How to keep $errors variable from being set as empty array

I have a fairly large site which I've recently moved to another server where it's been duplicated among a handful of VMs which all sit behind a load balancer. Since then, I've been spotting these errors in the logs.

Fatal error: Call to a member function has() on array (View: /var/www/sites/lotpro/public_html/resources/views/home.blade.php)

The offending line looks like the following:

<div class="form-group margin-sm ">

Keeping in mind this is Laravel 5.1, which is when everything is still stored in a singular routes.php file rather than split between web.php and api.php, I found this to be very strange, I shouldn't have to worry about giving my routes the correct middleware as it's already applied globally. The docs for 5.1 clearly state the $errors variable will always be available and will be an instance of MessageBag. In this case though, I was able to determine it's an empty array.

There are also similar occurrences in other files where I am also checking the $errors variable so I believe there isn't anything wrong with the code itself as I am unable to reproduce the issue.

I determined there may be an issue with the file session driver in regards to having the site behind a load balancer and running on multiple VMs so I spun up a shared Redis server and now I have the site using the redis session driver and it seems to have largely cleared up the issue. Unfortunately it does still very intermittently exist.

Each time we call a method on the $errors object, I could first check to see if it is an object, but that feels more like sweeping the issue under the rug and not actually fixing the underlying issue of not having a functioning session.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire