'How do I scale a server that has one database?
I am in the process of refactoring my server application/architecture to allow it to scale to many servers. However I can't think of any way to scale the account database/server application because it is the "one source of truth". In situations like this where there is one "core" database how do people usually go about making their architecture more scalable?
Solution 1:[1]
You have a single object $recipe that you are trying to loop on in your blade file.
This method:
public static function getRecipe($id)
{
return self::findOrFail($id);
}
returns the single object based on the $id. If you want a collection, skip the $id and use get() or all(), something like:
public function getRecipes(){
return self::all()
}
Or, just call it right in the controller without need for the method in the Model: $recipes = Recipe::all();
You can then loop on $recipes in the blade file because it is now a collection.
Solution 2:[2]
If you want to get all the "attributes" of the Model then you have to ask the Model for them; you can use the getAttributes method:
@foreach ($model->getAttributes() as $key => $value)
...
@endforeach
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 | Watercayman |
| Solution 2 | lagbox |
