/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, Post $post) { $post->update($request->except('tag_list', 'tag_list2', 'thumbnail', 'q')); $tags = $request->input('tag_list'); $tags2 = $request->input('tag_list2'); if (!empty($tags)) { foreach ($tags as $key => $name) { if (!is_numeric($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)) { $tag = \Model\Tag\Tag::firstOrNew(['name' => $name]); $tag->name = $name; $tag->save(); $tags2[$key] = $tag->id(); } } $post->tags()->sync($tags2); } // end if if ($request->hasFile('thumbnail')) { $file = $request->file('thumbnail'); $dir = 'img/thumbnail'; $btw = time(); $name = $post->id() . $btw . '.' . $file->getClientOriginalExtension(); Image::make($_FILES['thumbnail']['tmp_name'])->resize(250, 150)->save($dir . '/' . $name); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); $post->thumbnail = $dir . '/' . $name; $post->save(); } return redirect()->route('admin.post.show', $post); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, Post $post) { $post->update($request->except('tag_list', 'thumbnail', 'photo1', 'photo2', 'photo3', 'photo4', 'photo5', 'photo6', 'photo7', 'photo8', 'photo9', 'photo10')); $tags = $request->input('tag_list'); foreach ($tags as $key => $name) { if (!is_numeric($name)) { $tag = \Model\Tag\Tag::firstOrNew(['name' => $name]); $tag->name = $name; $tag->save(); $tags[$key] = $tag->id(); } } $post->tags()->sync($tags); if ($request->hasFile('thumbnail')) { $file = $request->file('thumbnail'); $dir = 'img/thumbnail'; $name = $post->id() . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); $post->thumbnail = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo1')) { $file = $request->file('photo1'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo1 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo2')) { $file = $request->file('photo2'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo2 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo3')) { $file = $request->file('photo3'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo3 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo4')) { $file = $request->file('photo4'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo4 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo5')) { $file = $request->file('photo5'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo5 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo6')) { $file = $request->file('photo6'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo6 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo7')) { $file = $request->file('photo7'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo7 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo8')) { $file = $request->file('photo8'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo8 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo9')) { $file = $request->file('photo9'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo9 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } if ($request->hasFile('photo10')) { $file = $request->file('photo10'); $dir = 'img/photogalery'; $time = rand(); $name = $time . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); // $storage->put($dir.'/'.$name, $file); $post->photo10 = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } return redirect()->route('admin.post.show', $post); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, Post $post) { $post->update($request->except('tag_kg', 'tag_ru', 'thumbnail', 'q', 'channel_id', 'created_at', 'time')); $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]); $post->tags()->sync($tagsCommon); if ($request->hasFile('thumbnail')) { $file = $request->file('thumbnail'); $dir = 'img/thumbnail'; $btw = time(); $name = $post->id() . $btw . '.' . $file->getClientOriginalExtension(); $name2 = $post->id() . $btw . '_big.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); Image::make($_FILES['thumbnail']['tmp_name'])->fit(250, 150)->save($dir . '/' . $name); Image::make($_FILES['thumbnail']['tmp_name'])->fit(500, 300)->save($dir . '/' . $name2); $post->thumbnail = $dir . '/' . $name; $post->thumbnail_big = $dir . '/' . $name2; $post->save(); } if ($request->input('channel_id') == null) { $channel_id = 1; $post->channel_id = $channel_id; } if ($request->input('created_at') != null) { $time = $request->input('time'); $postDate = $request->input('created_at'); $timeToSave = date('H:i:s', strtotime($time)); $saveDate = date('Y-m-d', strtotime($postDate)); $result = $saveDate . ' ' . $timeToSave; $post->created_at = $result; $post->save(); } else { $today = date('Y-m-d H:i:s'); dd($today); $post->created_at = date('Y-m-d H:i:s'); $post->save(); } return redirect()->route('admin.post.show', $post); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, Post $post) { $post->update($request->except('tag_list')); $tags = $request->input('tag_list'); foreach ($tags as $key => $name) { if (!is_numeric($name)) { $tag = \Model\Tag\Tag::firstOrNew(['name' => $name]); $tag->name = $name; $tag->save(); $tags[$key] = $tag->id(); } } $post->tags()->sync($tags); if ($request->hasFile('thumbnail')) { $file = $request->file('thumbnail'); $dir = 'img/banner'; $name = $post->id() . '.' . $file->getClientOriginalExtension(); $storage = \Storage::disk('public'); $storage->makeDirectory($dir); $post->thumbnail = $dir . '/' . $name; $post->save(); $file->move($dir, $name); } return redirect()->route('admin.post.show', $post); }