Skip to content
Advertisement

Laravel: Passing data into route from database

I have created a theme system and I am trying to make the theme’s route file pull pages from the database and assign a route to it, below is my theme route file. The issue I am having is an Undefined variable: theme from my ThemeSettings::all model request.

Route.php (In theme)

JavaScript

ThemeSettings Migration

JavaScript

These settings have worked in other parts of the site including in the admin area without issue, which is why I am confused.

Any help on this would be greatly appreciated! Thank you in advance!

Advertisement

Answer

$theme and $page are not scoped to the closure:

JavaScript

So, you make them accessible via use()

JavaScript

But, you have another problem:

JavaScript

Meaning accessing a property like $theme->location will cause an exception, as well.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement