I want to run an if statement over each of my posted requests and if any are a collection do something different.
When I die dump $request->all I have an array that looks like this;
"_token" => "MMRFBAgyThsIHzITzT26Qwdp4L6HDV0JTPGs6h"
"page_name" => "Travel"
"heading" => "Travel Europe"
"textarea" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostru ▶"
"seo_title" => "travel"
"seo_description" => "travel"
"attribute_1" => "Food"
"attribute_2" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor."
"attribute_3" => "Hotels"
"attribute_6" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor."
"attribute_5" => "Events"
"attribute_4" => "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor."
"attribute_7" => null
"attribute_8" => null
"attribute_9" => UploadedFile {#233 ▶}
The data will be different so I can't write anything static e.g.$request->input('attribute_9')
This is how I'm currently handling the attributes which are the unknown requests.
$input = $request->all();
foreach($input as $key=>$value) {
if(strstr($key,'attribute_')) {
$i = str_replace("attribute_", "", $key);
if (!empty($value)) {
if ($value instanceof Illuminate\Http\UploadedFile) {
dd('lets have a collection...');
}
Attribute::where('id', $i)->update(['value' => $value]);
} else{
Attribute::where('id', $i)->update(['value' => '']);
}
}
}
You can see I've tried to check the $value using instanceOf but that hasn't worked. The if statement is never true and the page just returns.
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2rjwCJG
via IFTTT
Aucun commentaire:
Enregistrer un commentaire