Я отправил несколько изображений в свою базу данных, и теперь я хочу отредактировать все изображения из своей базы данных, я обновил свой запрос, но не могу загрузить изображения в базу данных, есть 3 модели режима изображения Sitemap, модель изображения карты местоположения,модель изображения плана этажа, модель изображения свойства, и каждая модель связана с таблицей свойств, я уже написал код обновления своего свойства, но при обновлении контроллера я нахожу некоторую ошибку. Пожалуйста, проверьте мой код и дайте мне знать, где яЯ делаю ошибки в моем коде. Вот мой код для обновления ... UpdateController.php ..
public function update(Request $r, $property)
{
$validator = Validator::make($r->all(), [
'title' => 'required|unique:properties,title,'.$property.',propId|max:255',
// 'slug' => 'required|unique:properties,slug,'.$property.',propId|max:100',
'catId' => 'required|array|min:1',
]);
if ($validator->fails()){
return response()->json([$validator->errors()], 302);
}else{
$type = 'property';
$chr = substr($r->title, 0, 1);
if (!is_dir(public_path().'/'.$type)) {
$blogDir = public_path().'/'.$type;
mkdir ($blogDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd"))) {
$dateDir = public_path().'/'.$type.'/'.date("Ymd");
mkdir ($dateDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/thumb')) {
$thumbDir = public_path().'/'.$type.'/'.date("Ymd").'/thumb';
mkdir ($thumbDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/small')) {
$smallDir = public_path().'/'.$type.'/'.date("Ymd").'/small';
mkdir ($smallDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/thumb'.'/'.$chr)) {
$chrThumbDir = public_path().'/'.$type.'/'.date("Ymd").'/thumb'.'/'.$chr;
mkdir ($chrThumbDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/small'.'/'.$chr)) {
$chrSmallDir = public_path().'/'.$type.'/'.date("Ymd").'/small'.'/'.$chr;
mkdir ($chrSmallDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/floorPlan')) {
$floorPlanDir = public_path().'/'.$type.'/'.date("Ymd").'/floorPlan';
mkdir ($floorPlanDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/floorPlan'.'/'.$chr)) {
$chrFpDir = public_path().'/'.$type.'/'.date("Ymd").'/floorPlan'.'/'.$chr;
mkdir ($chrFpDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/locationImg')) {
$locationImg = public_path().'/'.$type.'/'.date("Ymd").'/locationImg';
mkdir ($locationImg, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/locationImg'.'/'.$chr)) {
$chrLmDir = public_path().'/'.$type.'/'.date("Ymd").'/locationImg'.'/'.$chr;
mkdir ($chrLmDir, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/sMImg')) {
$sMImg = public_path().'/'.$type.'/'.date("Ymd").'/sMImg';
mkdir ($sMImg, 0777, true);
}
if (!is_dir(public_path().'/'.$type.'/'.date("Ymd").'/sMImg'.'/'.$chr)) {
$chrsMImgDir = public_path().'/'.$type.'/'.date("Ymd").'/sMImg'.'/'.$chr;
mkdir ($chrsMImgDir, 0777, true);
}
/*=======================================
= Product Images =
=======================================*/
$thumbDirPath = date("Ymd").'/thumb/'.$chr;
$smallDirPath = date("Ymd").'/small/'.$chr;
if(var_dump($r->hasFile('propertyImages'))){
$propImage = [];
for ($v=0; $v < count($r->propertyImages); $v++) {
$thums = $r->propertyImages;
$filnameSmall = 'small-'.uniqid($chr).'-'.$v.'.'.$thums[$v]->getClientOriginalExtension();
$img = Image::make($thums[$v]->getRealPath());
$img->resize(300, null, function ($constraint) {
$constraint->aspectRatio();
});
$smallPath = public_path().'/test_img/'.$filnameSmall;
if (file_exists($smallPath)) {
unlink($smallPath);
}
$img->save($smallPath);
$optimizerChain = OptimizerChainFactory::create();
$optimizerChain->optimize($smallPath);
$filnameLarge = 'thumb-'.uniqid($chr).'-'.$v.'.'.$thums[$v]->getClientOriginalExtension();
$img = Image::make($thums[$v]->getRealPath());
$img->resize(1080, 420, function ($constraint) {
$constraint->aspectRatio();
});
$thumbPath = public_path().'/test_img/'.$filnameSmall;
if (file_exists($thumbPath)) {
unlink($thumbPath);
}
$img->save($thumbPath);
$optimizerChain->optimize($thumbPath);
$propImage[$v]['small'] = $filnameSmall;
$propImage[$v]['smallDirPath'] = $smallDirPath;
$propImage[$v]['large'] = $filnameLarge;
$propImage[$v]['thumbDirPath'] = $thumbDirPath;
}
}
else{
$propImage = NULL;
}
$floorPlanDirPath = date("Ymd").'/floorPlan/'.$chr;
if($r->file('floorPlan')){
$floor = [];
for ($v=0; $v < count($r->floorPlan); $v++) {
$thums = $r->floorPlan;
$floorPlan = 'floor_plan-'.uniqid($chr).'-'.$v.'.'.$thums[$v]->getClientOriginalExtension();
$img = Image::make($thums[$v]->getRealPath());
$img->resize(1080, null, function ($constraint) {
$constraint->aspectRatio();
});
$thumbPath = public_path().'/'.$type.'/'.date("Ymd").'/floorPlan'.'/'.$chr.'/'.$floorPlan;
if (file_exists($thumbPath)) {
$this->removeImage($thumbPath);
}
$img->save($thumbPath);
$optimizerChain->optimize($thumbPath);
$floor[$v]['floor_plan'] = $floorPlan;
$floor[$v]['floorPlanPath'] = $floorPlanDirPath;
}
}else{
$floor = NULL;
}
$sMImgDirPath = date("Ymd").'/sMImg/'.$chr;
if($r->hasFile('location_images')){
$sm = [];
for ($v=0; $v < count($r->siteMapImg); $v++) {
$thums = $r->siteMapImg;
$siteMapImage = 'site_map_image-'.uniqid($chr).'-'.$v.'.'.$thums[$v]->getClientOriginalExtension();
$img = Image::make($thums[$v]->getRealPath());
$img->resize(1080, null, function ($constraint) {
$constraint->aspectRatio();
});
$thumbPath = public_path().'/'.$type.'/'.date("Ymd").'/sMImg'.'/'.$chr.'/'.$siteMapImage;
if (file_exists($thumbPath)) {
$this->removeImage($thumbPath);
}
$img->save($thumbPath);
$optimizerChain->optimize($thumbPath);
$sm[$v]['siteMap'] = $siteMapImage;
$sm[$v]['siteMapPath'] = $sMImgDirPath;
}
}else{
$sm = NULL;
}
if($propImage && count($propImage)!=NULL){
for ($v=0; $v< count($propImage); $v++) {
$prop->proImage()->create()([
'small_thumb' => $propImage[$v]['small'],
'small_thumb_url' => $propImage[$v]['smallDirPath'],
'large_thumb' => $propImage[$v]['large'],
'large_thumb_url' => $propImage[$v]['thumbDirPath'],
]);
}}
for ($v=0; $v < empty($floor); $v++) {
$prop->floorPlan()->create([
'floor_plan' => $floor[$v]['floor_plan'],
'floorPlanPath' => $floor[$v]['floorPlanPath']
]);
}
/*=============================================
= Location Image =
=============================================*/
$locationImgDirPath = date("Ymd").'/locationImg/'.$chr;
if($r->file('location_images')){
$locn = [];
$thums = $r->location_images;
$locationImg = 'location_image'.uniqid($chr).'-'.$v.'.'.$thums[$v]- >getClientOriginalExtension();
$img = Image::make($thums[$v]->getRealPath());
$img->resize(1080, null, function ($constraint) {
$constraint->aspectRatio();
});
$thumbPath = public_path().'/'.$type.'/'.date("Ymd").'/locationImg'.'/'.$chr.'/'.$locationImg;
if (file_exists($thumbPath)) {
$this->removeImage($thumbPath);
}
if(!empty($thumbPath)) {
if (file_exists(public_path('property_img/'.$thumbPath))) { // unlink or remove previous image from folder
unlink(public_path('property_img/'.$thumbPath));
}
}
$img->save($thumbPath);
$optimizerChain->optimize($thumbPath);
$locn[$v]['location_image'] = $locationImg;
$locn[$v]['locationImgPath'] = $locationImgDirPath;
}else{
$locn = NULL;
}
if ($locn && count($locn) == 1) {
for ($v=0; $v < count($locn); $v++) {
$prop->mapImage()->create([
'location_image' => $locn[$v]['location_image'],
'locationImgPath' => $locn[$v]['locationImgPath']
]);
}
}
/*===== End of Location Image ======*/
if($sm && count($sm) == 1){
for ($v=0; $v < count($sm); $v++) {
$prop->siteMapImage()->create([
'siteMap' => $sm[$v]['siteMap'],
'siteMapPath' => $sm[$v]['siteMapPath']
]);
}
}
$prop->save();
return redirect()->back();
}
}