In my application, when the form is submitted, the $_POST items are stored here in my controller;
$input = Request::except('postcode_id'); //all the input from the form except postcode_id
A print_r of that will look like this;
Array
(
[country] => Array
(
[0] => E92000001
[1] => L93000001
)
[county] => Array
(
[0] => E10000003
[1] => E10000006
)
)
country
and county
have their own models, called Country and County respectively. How can I call this within a loop in my controller to access those models?
I was thinking something like;
foreach ($input as $key => $value) {
foreach ($value as $subkey => $subvalue) {
$ucfirst = ucfirst($key); //Try turning `country` in to `Country`
$selection = $ucfirst::description($subvalue)->get()->first();
}
}
But that gave me an error of Class 'Country' not found
The description
method in that loop is a Scope
by the way. Here is the from the Country model;
public function scopeDescription($query, $code)
{
$query->where('code', '=', $code);
}
I just need a way of looping through what was selected on the form. Each field is a multi select dropdown. And each field is a table in the database.