/**
  * 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');
 }
Esempio n. 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');
 }
Esempio n. 3
0
 public function store(PostRequest $request, PhotoGestion $photoGestion)
 {
     if ($photoGestion->save($request->file('photo'))) {
         $input = $request->all();
         $input['photo'] = $photoGestion->getPictureLink();
         $inputs = array_merge($input, ['user_id' => $request->user()->id]);
         /*return 'Le formulaire est bien rempli avec : 
         		nom = '.$inputs['user_id'].'
         		type = '.$inputs['type'].'
         		postPicture = '.$inputs['photo'].'
         		photo = '.$photoGestion->getPictureLink().'
         		etat = '.$inputs['etat']; */
         $posts = $this->postRepository->store($inputs);
         //$posts['photo'] = $photoGestion->getPictureLink();
         return redirect(route('post.index'));
     }
     //$inputs = array_merge($request->all(), ['user_id' => $request->user()->id]);
     //$this->postRepository->store($inputs);
     //return redirect(route('post.index'));
 }
Esempio n. 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', 'Объявление добавлено!');
 }
Esempio n. 5
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Requests\PostRequest $request, $id)
 {
     $post = Posts::where('id', $id)->firstOrFail();
     if (!empty($request->file('image')) && $request->file('image')->isValid()) {
         $destinationPath = public_path() . "/images/";
         // upload path
         $extension = $request->file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = $post->url . '.' . $extension;
         // renameing image
         $request->file('image')->move($destinationPath, $fileName);
         // uploading file to given path
         $post->image = $fileName;
     }
     $post->fill($request->only(['title', 'post']));
     $post->save();
     Posts::findOrFail($id)->tags()->detach();
     $tags = [];
     foreach ($this->getTags($request->input('tags')) as $tag) {
         if (!empty($tag)) {
             $isFind = Tags::where('name', $tag)->get()->count();
             if ($isFind == 0) {
                 $tags[] = new Tags(['name' => $tag]);
             } else {
                 $tags[] = Tags::where('name', $tag)->first();
             }
         }
     }
     $post->tags()->saveMany($tags);
     return back();
 }
Esempio n. 6
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');
 }