I'm trying to save little pieces of data to the database. For example a phone number, just a value of something i only need one of. I have written some example code to show what i want at the end but not sure if it is the best/only way:
public function index(){
$customFields = customFields::all();
$fields = [];
foreach($customFields as $customField){
$field[$customField['name']] = $customField['value'];
}
}
Alright, the create function which you've put in the foreach isn't needed, the create function will be in the create function of the controller. The reason i loop them through a new made array is to use the key from the database to use that as the name which contains the value. And because i don't want to loop through the custom fields in the view, i just want to place them mannually.
public function index(){
$customFields = customField::all();
$fields = [];
foreach($customFields as $customField){
$field[$customField['name']] = $customField['value'];
}
}
<p>{{$field['location']}}</p>