Every Laravel developer meets this error sooner or later:
ErrorException: Undefined variable $products
The page was fine yesterday, or it never worked at all, and the message gives you almost nothing to go on. Here is the thing most beginners miss: the error is almost never a Blade problem. It is a data-passing problem. A Blade template can only use variables that were explicitly handed to it. Your controller, your model, and your other views do not share scope with it.
Before you start changing code, check these five spots in order. In my experience the bug is in one of them almost every time.
The controller never passed it. The controller fetches the data and then renders the view without it. Open the method behind the route and look at the view() call. If the variable is not in the second argument, that is your bug. Pass it with an array, compact(), or with() β all three work, just pick one style per project.
The name does not match. The controller passes product and the view loops over $products.β¦