'app() helper return different structure on server
i have this code
app('getHomeContent')
locally it returns
{#2999 ▼
+"slider_title": "For every student, every classroom. Real results."
+"slider_text": "Build skills with courses, certificates, and degrees online from world-class universities and companies"
+"testimonial_title": "What Our Student Have To Say"
...
but on server return
{#2999 ▼
+"main": array:127 [▼
+"slider_title": "For every student, every classroom. Real results."
+"slider_text": "Build skills with courses, certificates, and degrees online from world-class universities and companies"
+"testimonial_title": "What Our Student Have To Say"
....
the added "main:" causes issues as locally i don't have to type it at all to access the data ! how to fix this ? what makes response different from server to local
Solution 1:[1]
I think there's a better way to go about this, instead of using app() to get content.
Here's what I would suggest so you get the same results everytime.
First, create a helper.php file in your app directory.
Second, add the following code in the helper.php file:
<?php
function getHomeContent() {
return [
'slider_title' => 'title',
'slider_text' => 'text',
...
]
}
Finally, go to your composer.json file and add the following
"autoload": {
...
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
},
"files": [
"app/helper.php" // <---- this file
]
},
After doing composer dump, you can go anywhere and use getHomeContent() directly.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Taylor |
