/**
  * Store a new App\Post
  */
 public function store(PostRequest $request)
 {
     logThis(auth()->user()->name . ' created a new post called ' . $request->title);
     $post = auth()->user()->posts()->create($request->all());
     if ($request->hasFile('myfiles')) {
         $post->addFiles($request->file('myfiles'));
     }
     flash()->success('Created!', $post->title . ' has been created.');
     return redirect()->route('posts.index');
 }
示例#2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(PostRequest $request, $id)
 {
     $post = Post::findOrNew($id);
     $post->update($request->all());
     if ($request->hasFile('link_thumbnail')) {
         $file = $request->file('link_thumbnail');
         $ext = $file->getClientOriginalExtension();
         $fileName = str_random(12) . '.' . $ext;
         $file->move('assets/img/confs', $fileName);
         $post->link_thumbnail = $fileName;
         $post->save();
     }
     return redirect('/dashboard');
 }
示例#3
0
 /**
  * Update the Post
  *
  * @param Request $request
  * @param int  $id
  */
 public function update(PostRequest $request, $id)
 {
     $post = Post::findOrFail($id);
     $images = $post->images;
     $post->fill($request->postFillData(Post::class));
     if ($request->hasFile('images')) {
         // delete file
         $path = $this->getPath();
         if ($images && \File::exists($path . $images)) {
             \File::delete($path . $images);
             \File::delete($path . 'thumb/' . $images);
         }
         $post->images = $this->uploadImage($request);
     } else {
         $post->images = $images;
     }
     $post->save();
     if ($request->action === 'continue') {
         return redirect()->back()->withSuccess('Post saved.');
     }
     return redirect()->route('admin.post.index')->withSuccess('Post saved.');
 }
示例#4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(PostRequest $request, $id)
 {
     $post = Auth::user()->posts()->find($id);
     if ($request->hasFile('images')) {
         $i = 0;
         $introImage = null;
         $images = unserialize($post->images) ? unserialize($post->images) : [];
         foreach ($request->file('images') as $key => $image) {
             if (isset($image)) {
                 $imageName = $key . '-image-' . str_random(10) . '.' . $image->getClientOriginalExtension();
                 if (!file_exists('img/posts/' . $post->user_id)) {
                     Storage::makeDirectory('img/posts/' . $post->user_id);
                 }
                 if ($key == 0) {
                     if ($post->image != NULL and file_exists('img/posts/' . $post->user_id . '/' . $post->image)) {
                         Storage::delete('img/posts/' . $post->user_id . '/' . $post->image);
                     }
                     $mainFile = Image::canvas(300, 200, '#ffffff');
                     $introFile = Image::make($image);
                     $this->file = $introFile;
                     $this->optimalResize(300, 200);
                     $mainFile->insert($this->file, 'center');
                     $mainFile->rectangle(0, 0, 299, 199, function ($draw) {
                         $draw->border(1, '#dddddd');
                     });
                     $mainFile->save('img/posts/' . $post->user_id . '/main-' . $imageName);
                     $introImage = 'main-' . $imageName;
                 }
                 // Creating images
                 $moreFile = Image::canvas(634, 432, '#ffffff');
                 $file = Image::make($image);
                 $this->file = $file;
                 $this->optimalResize(634, 432);
                 $moreFile->insert($this->file, 'center');
                 $moreFile->insert('img/watermark-blue.png', 'bottom-left', 10, 10);
                 $moreFile->rectangle(0, 0, 633, 431, function ($draw) {
                     $draw->border(1, '#dddddd');
                 });
                 $moreFile->save('img/posts/' . $post->user_id . '/' . $imageName);
                 // Creating mini images
                 $miniFile = Image::canvas(95, 71, '#ffffff');
                 $this->file = $file;
                 $this->optimalResize(95, 71);
                 $miniFile->insert($this->file, 'center');
                 $miniFile->rectangle(0, 0, 94, 70, function ($draw) {
                     $draw->border(1, '#dddddd');
                 });
                 $miniFile->save('img/posts/' . $post->user_id . '/mini-' . $imageName);
                 if (isset($images[$key])) {
                     Storage::delete(['img/posts/' . $post->user_id . '/' . $images[$key]['image'], 'img/posts/' . $post->user_id . '/' . $images[$key]['mini_image']]);
                     $images[$key]['image'] = $imageName;
                     $images[$key]['mini_image'] = 'mini-' . $imageName;
                 } else {
                     $images[$key]['image'] = $imageName;
                     $images[$key]['mini_image'] = 'mini-' . $imageName;
                 }
             }
         }
         $images = array_sort_recursive($images);
         $images = serialize($images);
     }
     $post->city_id = $request->city_id;
     $post->category_id = $request->category_id;
     $post->slug = str_slug($request->title);
     $post->title = $request->title;
     $post->price = $request->price;
     $post->deal = $request->deal;
     $post->description = $request->description;
     if (isset($introImage)) {
         $post->image = $introImage;
     }
     if (isset($images)) {
         $post->images = $images;
     }
     $post->address = $request->address;
     $contacts = ['phone' => $request->phone, 'telegram' => $request->telegram, 'whatsapp' => $request->whatsapp, 'viber' => $request->viber, 'phone2' => $request->phone2, 'telegram2' => $request->telegram2, 'whatsapp2' => $request->whatsapp2, 'viber2' => $request->viber2];
     $post->phone = json_encode($contacts);
     $post->email = $request->email;
     $post->comment = $request->comment;
     if ($tags_id = $request->input('tags_id')) {
         $post->detachTags();
         $post->attachTags($tags_id);
     }
     $post->save();
     return redirect('my_posts')->with('status', 'Объявление добавлено!');
 }
示例#5
0
 /**
  * Update the specified resource in storage.
  *
  * @param  PostRequest  $request
  * @param  int  $id
  * @return Response
  */
 public function update(PostRequest $request, $id)
 {
     $post = Post::find($id);
     $data = $request->all();
     $data['user_id'] = Auth::user()->id;
     $post->update($data);
     $post->tags()->sync($request->input('tags'));
     if ($request->hasFile('thumbnail_link')) {
         $file = $request->file('thumbnail_link');
         $ext = $file->getClientOriginalExtension();
         $fileName = str_random(12) . '.' . $ext;
         ImageManagerStatic::make($file)->fit(200, 150)->save(public_path() . "/upload/" . $fileName);
         $post->thumbnail_link = $fileName;
         $post->save();
     }
     return redirect()->to('post')->with('message', 'Mise à jour de la conférence avec succès');
 }