コード例 #1
0
ファイル: PhotoChildController.php プロジェクト: elemanz/ktrk
 public function update(Request $request, PhotoChild $photoChild)
 {
     $photoChild->update($request->except('file', 'tag_kg', 'tag_ru', 'q'));
     $tag_kg_string = $request->input('tag_kg');
     $tags = explode("; ", $tag_kg_string);
     $tag_ru_string = $request->input('tag_ru');
     $tags2 = explode("; ", $tag_ru_string);
     if (!empty($tags)) {
         foreach ($tags as $key => $name) {
             if (!is_numeric($name) && !empty($name)) {
                 $tag = \Model\Tag\Tag::firstOrNew(['name' => $name]);
                 $tag->name = $name;
                 $tag->save();
                 $tags[$key] = $tag->id();
             }
         }
         //            $post->tags()->sync($tags);
     }
     // end if
     if (!empty($tags2)) {
         foreach ($tags2 as $key => $name) {
             if (!is_numeric($name) && !empty($name)) {
                 $tag = \Model\Tag\Tag::firstOrNew(['name' => $name]);
                 $tag->name = $name;
                 $tag->save();
                 $tags2[$key] = $tag->id();
             }
         }
         //            $post->tags()->sync($tags2);
     }
     // end if
     $tagsCommon = array_collapse([$tags, $tags2]);
     $photoChild->tags()->sync($tagsCommon);
     if ($request->hasFile('file')) {
         $file = $request->file('file');
         $time = time();
         $dir = 'froala/uploads';
         $name = $photoChild->id() . $time . '.' . $file->getClientOriginalExtension();
         $storage = \Storage::disk('public');
         $storage->makeDirectory($dir);
         Image::make($_FILES['file']['tmp_name'])->heighten(600)->save($dir . '/' . $name);
         $photoChild->file = $dir . '/' . $name;
         $photoChild->save();
     }
     return redirect()->route('admin.photoChild.show', $photoChild);
 }