Search code examples
phparrayslaravellaravel-5laravel-5.3

array variable available sitewide in a custom configuration file - Laravel


I am trying to store an array in a config file `config/project_specific.php

<?php

return [
    'sluggable_models1' => 'test_value', // works
    'sluggable_models2' => ['features','packages'], // throws error
];

I call this value by $models = config('project_specific.sluggable_models') in my controller

problem

as long as the variable is a string, it works. When the value is an array type, i get this error ErrorException in helpers.php line 515: htmlentities() expects parameter 1 to be string, array given (View: \resources\views\starter\admin\dashboard_admintools.blade.php)

to do

how I can store a sitewide accessible array in my Laravel 5.3 app? Not necesarily a config file, but I prefer to avoid a DB-fed solution.


Solution

  • The error seems to indicate the array is making it to your view just fine but you are trying to print the variable in your blade template vs. looping over it.

    {{ }} is essentially the same as echo but it tries to escape the string using htmlentities(), hence the error.