Exemplo n.º 1
0
 public function create(Request $request)
 {
     $article = new \App\Article(['title' => $request['title'], 'content' => $request['content'], 'description' => $request['description'], 'views' => 0, 'user_id' => auth()->user()->id, 'blog_id' => 1, 'category_id' => $request['category'] ? $request['category'] : 0]);
     $article->save();
     $array = explode(',', $request->tags);
     foreach ($array as $tag) {
         if (filter_var($tag, FILTER_VALIDATE_INT)) {
             $article->tags()->attach($tag);
         } else {
             $newTag = Tag::create(['name' => $tag]);
             $article->tags()->attach($newTag['id']);
         }
     }
     return redirect()->back()->with(['alert' => true, 'update' => true, 'class' => 'success', 'message' => 'Article crée avec succèss']);
 }
Exemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  ArticleRequest  $request
  * @param  Article $article
  * @return Response
  */
 public function update(ArticleRequest $request, Article $article)
 {
     $article->update($request->all());
     $article->tags()->sync($request->get('tag_list'));
     session()->flash('success', 'Запись ' . $request->get('title') . ' обновлена');
     return redirect()->route('article.index');
 }
Exemplo n.º 3
0
 public function update(Article $article, ArticleRequest $request)
 {
     // $article = Article::findOrFail($id);
     $article->update($request->all());
     $article->tags()->sync($request->input('tag_list'));
     return redirect('articles');
 }
Exemplo n.º 4
0
 public function store(ArticleRequest $request)
 {
     // Request use
     //		$input = Request::all();
     // check data input :: use ArticleRequest class
     //		$input = $request->all();
     //		Article::create($input);
     $article = new Article($request->all());
     // add image
     if ($request->hasFile('image')) {
         $image_filename = $request->file('image')->getClientOriginalName();
         $image_name = date("Ymd-His-") . $image_filename;
         $public_path = 'images/articles/';
         $destination = base_path() . $public_path;
         $request->file('image')->move($destination, $image_name);
         $article->image = $public_path . $image_name;
     }
     // add migration user_id
     /* form 1 */
     $article->user_id = Auth::user()->id;
     $article->save();
     /* form 2 */
     //		Auth::user()->articles()->save($article);
     // add many to many
     $tagsId = $request->input('tag_list');
     if (!empty($tagsId)) {
         $article->tags()->sync($tagsId);
     }
     return redirect('articles');
 }
Exemplo n.º 5
0
 /**
  * Include tags.
  *
  * @param  \App\Article                  $article
  * @param  \League\Fractal\ParamBag|null $params
  * @return  \League\Fractal\Resource\Collection
  * @throws  \Exception
  */
 public function includeTags(Article $article, ParamBag $params = null)
 {
     $transformer = new \App\Transformers\TagTransformer($params);
     $parsed = $this->getParsedParams();
     $tags = $article->tags()->limit($parsed['limit'])->offset($parsed['offset'])->orderBy($parsed['sort'], $parsed['order'])->get();
     return $this->collection($tags, $transformer);
 }
Exemplo n.º 6
0
 public function update(Article $article, ArticleRequest $request)
 {
     $article->update($request->all());
     $article->tags()->sync($request->input('tag_list', []));
     \Flash::success('記事を更新しました。');
     return redirect()->route('articles.show', [$article->id]);
 }
 public function update(Article $article, Requests\ArticleRequest $request)
 {
     //type hinting ArticleRequest lets us do validation
     //$article = Article::findOrFail($id);
     $article->update($request->all());
     $article->tags()->sync($request->input('tag_list'));
     return redirect('articles');
 }
Exemplo n.º 8
0
 /**
  * Stubbing test data.
  *
  * @param array $overrides
  */
 protected function createTestStub($overrides = [])
 {
     $this->user = !empty($overrides) ? factory(User::class)->create() : factory(User::class)->create($overrides);
     $this->user->attachRole(Role::find(2));
     $this->article = factory(Article::class)->create(['title' => 'title', 'author_id' => $this->user->id, 'content' => 'description']);
     $this->article->comments()->save(factory(Comment::class)->make(['author_id' => $this->user->id]));
     $this->article->tags()->attach(1);
     $this->article->attachments()->save(factory(Attachment::class)->make());
 }
Exemplo n.º 9
0
 private function syncTags(Article $article, array $tags)
 {
     $currentTags = array_filter($tags, 'is_numeric');
     $newTags = array_diff($tags, $currentTags);
     foreach ($newTags as $newTag) {
         $tag = Tag::create(['name' => $newTag]);
         $tag->save();
         $currentTags[] = $tag->id;
     }
     $article->tags()->sync($currentTags);
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     $faker = Faker\Factory::create();
     DB::statement('set foreign_key_checks = 0');
     Article::truncate();
     DB::statement('set foreign_key_checks = 1');
     foreach (range(1, 30) as $index) {
         $article = new Article();
         $article->user_id = mt_rand(1, 2);
         $article->title = $faker->sentence(2);
         $article->body = $faker->sentence(20);
         $article->published_at = Carbon\Carbon::now()->subDays(mt_rand(0, 3650));
         $article->save();
         $article->tags()->attach($this->getRandomTagList());
     }
     Model::reguard();
 }
Exemplo n.º 11
0
 public function store(ArticleRequest $request)
 {
     if ($request->file('image')) {
         $file = $request->file('image');
         $name = "blogfacilito_" . time() . bcrypt(\Auth::user()) . "." . $file->getClientOriginalExtension();
         $path = public_path() . "/images/articles/";
         $file->move($path, $name);
     }
     $article = new Article($request->all());
     $article->user_id = \Auth::user()->id;
     $article->save();
     $article->tags()->sync($request->tags);
     $image = new Image();
     $image->name = $name;
     $image->article()->associate($article);
     $image->save();
     Flash::success("El articulo " . $article->title . " se ha creado satisfactoriamente!");
     return redirect()->route('admin.articles.index');
 }
Exemplo n.º 12
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ArticleRequest $request)
 {
     if ($request->file('image')) {
         $file = $request->file('image');
         $name = 'blogfacilito_' . time() . '.' . $file->getClientOriginalExtension();
         $path = public_path() . '/images/articles/';
         $file->move($path, $name);
     }
     $article = new Article($request->all());
     $article->user_id = \Auth::user()->id;
     $article->save();
     $article->tags()->sync($request->tags);
     $image = new Image();
     $image->name = $name;
     $image->article()->associate($article);
     $image->save();
     Flash::success('Se ha creado el articulo ' . $article->title . ' de forma exitosa!!');
     return redirect()->route('admin.articles.index');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ArticleRequest $request)
 {
     //Img handle
     if ($request->file('image')) {
         $file = $request->file('image');
         $name = 'laravel_' . time() . '.' . $file->getClientOriginalExtension();
         $path = public_path() . '\\images\\articles\\';
         $file->move($path, $name);
     }
     $article = new Article($request->all());
     $article->user_id = \Auth::user()->id;
     $article->save();
     $article->tags()->sync($request->tags);
     $image = new Image();
     $image->name = $name;
     $image->article()->associate($article);
     $image->save();
     Flash::success('Se ha creado el artículo ' . $article->title . ' correctamente.');
     return redirect()->route('admin.articles.index');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ArticleRequest $request)
 {
     // Manipulacion de imagenes
     if ($request->file('image')) {
         $file = $request->file('image');
         $name = 'IN_' . time() . '.' . $file->getClientOriginalExtension();
         $path = public_path() . '/images/articles/';
         $file->move($path, $name);
     }
     $article = new Article($request->all());
     $article->user_id = \Auth::user()->id;
     $article->save();
     $article->tags()->sync($request->tags);
     $image = new Image();
     $image->name = $name;
     $image->article()->associate($article);
     $image->save();
     alert()->success('Enorabuena', 'El articulo ' . $article->title . ' ha sido creado con exito');
     Flash::success('El articulo ' . $article->title . ' ha sido creado con exito¡');
     return redirect()->route('admin.articles.index');
 }
Exemplo n.º 15
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(ArticleRequest $request)
 {
     //Manipulación de imagenes
     if ($request->file('image')) {
         $file = $request->file('image');
         $name = 'blogPrueba_' . time() . '.' . $file->getClientOriginalExtension();
         $path = public_path() . '/images/articles/';
         $file->move($path, $name);
     }
     $article = new Article($request->all());
     $article->user_id = \Auth::user()->id;
     $article->save();
     //Rellenar tabla pivote Article_tag
     $article->tags()->sync($request->tags);
     $image = new Image();
     $image->name = $name;
     $image->article()->associate($article);
     $image->save();
     Flash::success("Se ha creado el articulo  " . $article->title . "con exito");
     return redirect()->route('admin.articles.index');
 }
 public function store(ArticleRequest $request)
 {
     if ($request->file('image')) {
         //Manipulacion de imagenes
         $file = $request->file('image');
         $name = substr($file->getClientOriginalName(), 0, -4) . "_" . time() . '_image.' . $file->getClientOriginalExtension();
         $path = base_path() . '/public/images/articles/';
         $file->move($path, $name);
         $image->name = $name;
     }
     $article = new Article($request->all());
     $article->user_id = \Auth::user()->id;
     $article->save();
     $article->tags()->sync($request->tags);
     $image = new Image();
     $image->article_id = $article->id;
     //$image->article()->associate();
     $image->save();
     Flash::success('Se ha agregado el articulo de forma satisfactoria.');
     return redirect()->route('admin.articles.index');
 }
Exemplo n.º 17
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     // Manipulación de imágenes
     if ($request->file('image')) {
         $file = $request->file('image');
         $name = 'blog_' . time() . '.' . $file->getClientOriginalExtension();
         $path = public_path() . '/images/articles/';
         $file->move($path, $name);
     }
     // NOTA : Se deben instanciar los modelos para poder acceder a las propiedades que no están en el formlario
     $article = new Article($request->all());
     $article->user_id = Auth::user()->id;
     $article->save();
     //El método "sync", nos permite llenar la tabla pivote, recibe como parámetro un array con los datos que se van a rellenar
     $article->tags()->sync($request->tags);
     $image = new Image();
     $image->name = $name;
     $image->article()->associate($article);
     $image->save();
     Session::flash('message_create', "El Artículo - " . $request->title . " - fue creado exitosamente!");
     return redirect()->route('admin.articles.index');
 }
Exemplo n.º 18
0
 /**
  * Sync up the array of tags in the databse
  * @param Article $article
  * @param ArticleRequest $request
  */
 private function syncTags(Article $article, $tags)
 {
     if (count($tags) >= 1 && !is_null($tags)) {
         $article->tags()->sync($tags);
     }
 }
Exemplo n.º 19
0
 public function syncTags(Article $article, $tags = array(), $isNew = false)
 {
     $tagall = Tag::all()->toArray();
     $newTagIds = $updateTagIds = $existingSlug = $existingTag = [];
     if (!empty($tagall)) {
         foreach ($tagall as $tag) {
             $existingSlug[] = $tag['slug'];
             $existingTag[$tag['slug']] = $tag;
         }
     }
     unset($tagall);
     if ($tags) {
         foreach ($tags as $tag) {
             if (!in_array(mb_strtolower($tag, 'UTF-8'), $existingSlug)) {
                 $name = filter_allowed_words($tag);
                 $slug = preg_replace('/\\s+/', '-', mb_strtolower($name, 'UTF-8'));
                 if (in_array($slug, $existingSlug)) {
                     if ($isNew) {
                         Tag::whereSlug($slug)->increment('count');
                     }
                     $updateTagIds[] = $existingTag[$slug]['id'];
                 } else {
                     $firstLetter = getFirstLetter($name);
                     $newtag = Tag::create(array('name' => $name, 'slug' => $slug, 'letter' => $firstLetter));
                     $newId = $newtag->id;
                     $newTagIds[] = $newId;
                     $updateTagIds[] = $newId;
                 }
             } else {
                 if ($isNew) {
                     Tag::whereSlug($tag)->increment('count');
                 }
                 $updateTagIds[] = $existingTag[$tag]['id'];
             }
         }
     }
     $updateTagIds = array_unique($updateTagIds);
     if (!$isNew) {
         $oldTagIds = $article->tags->lists('id')->toArray();
         $delTagIds = array_diff($oldTagIds, $updateTagIds);
         $addTagIds = array_diff($updateTagIds, $oldTagIds);
         if (!empty($delTagIds)) {
             Tag::whereIn('id', $delTagIds)->decrement('count');
         }
         if (!empty($addTagIds)) {
             foreach ($addTagIds as $addId) {
                 if (!in_array($addId, $newTagIds)) {
                     Tag::whereId($addId)->increment('count');
                 }
             }
         }
     }
     $article->tags()->sync($updateTagIds);
     unset($newTagIds, $updateTagIds, $existingSlug, $existingTag);
 }
Exemplo n.º 20
0
 /**
  * Sync up the list of tags in the database
  *
  * @param Article $article
  * @param array $tags
  */
 private function syncTags(Article $article, array $tags)
 {
     //sync the tags we have in the updated request with the tags in the db
     //that are within the article_tag pivot table
     $article->tags()->sync($tags);
 }
 public function update(Article $article, ArticleRequest $request)
 {
     $article->update($request->all());
     $article->articleImages()->delete();
     if (count($request->eyecatch) > 0) {
         foreach ($request->eyecatch as $key => $eyecatch) {
             $articleImage = new ArticleImage(['eyecatch' => $eyecatch]);
             $article->articleImages()->save($articleImage);
         }
     }
     $article->tags()->sync($request->input('tag_list', []));
     \Flash::success('記事を更新しました。');
     // return redirect()->route('articles.show', [$article->id]);
 }
Exemplo n.º 22
0
 public function update(Article $article, Request $request)
 {
     $user = $this->user;
     //dd($request->all());
     $this->validate($request, ['title' => 'required|min:3', 'published' => 'required|in:0,1', 'content' => 'required|min:3', 'image' => 'mimes:jpeg,bmp,png,jpg|max:1024', 'tags.*' => 'min:2|max:30', 'categories.*' => 'integer']);
     $input = $request->all();
     $previousImage = $article->image;
     /* check if the user has uploaded image or not */
     if ($request->hasFile('image')) {
         $image = $input['image'];
         $imageName = $user->id . str_random(20) . '.' . $image->getClientOriginalExtension();
         $imageDbName = $user->id . '/' . $imageName;
         $image->move(public_path() . '/img/files/' . $user->id, $imageName);
         /* Delete the previous image */
         if ($previousImage != null) {
             if (File::exists(public_path() . '/img/files/' . $user->id . '/' . $previousImage)) {
                 unlink(public_path() . '/img/files/' . $user->id . '/' . $previousImage);
             }
         }
     } else {
         $imageDbName = $previousImage;
     }
     /*update article*/
     $article->update(['title' => $input['title'], 'content' => $input['content'], 'published' => $input['published'], 'image' => $imageDbName]);
     /*register subCategories*/
     $selectedCategories = $this->registerSubCategories($request);
     if (!$selectedCategories) {
         //if the selected tags has error
         return redirect()->back();
     }
     $article->categories()->sync($selectedCategories);
     /*register tags*/
     $selected = $this->registerTags($request);
     $article->tags()->sync($selected);
     Flash::success(trans('users.articleEdited'));
     return redirect()->back();
 }
Exemplo n.º 23
0
 private function syncTags(Article $article, $tags)
 {
     $article->tags()->sync(!$tags ? [] : $tags);
 }
 /**
  * @param Article $article
  * @param $tags
  * @internal param ArticleRequest $request
  */
 private function syncTags(Article $article, $tags)
 {
     $article->tags()->sync((array) $tags);
 }
Exemplo n.º 25
0
 /**
  * Sync up the list of tags in the database.
  *
  * @param Article $article
  * @param array $tags
  */
 private function syncTags(Article $article, array $tags)
 {
     $article->tags()->sync($tags);
 }
Exemplo n.º 26
0
 public function syncTags(Article $article, array $tags)
 {
     foreach ($tags as $key => $tag) {
         if (!is_numeric($tag)) {
             $newTag = Tag::create(['name' => $tag]);
             $tags[$key] = $newTag->id;
         }
     }
     $article->tags()->sync($tags);
 }
Exemplo n.º 27
0
 /**
  * @param Article $article
  * @param $tags
  */
 protected function processTags($article, $tags)
 {
     if (is_string($tags)) {
         $_tags = explode(',', $tags);
     } else {
         $_tags = $tags;
     }
     $tags = [];
     foreach ($_tags as $_tag) {
         $tag = $article->tags()->firstOrCreate(['name' => trim($_tag)]);
         array_push($tags, $tag->getKey());
     }
     $article->tags()->sync($tags, true);
 }
Exemplo n.º 28
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy(Article $article)
 {
     $deleteText = '';
     if ($article->deleteImages()) {
         $deleteText = 'and successfully deleted the files!';
     } else {
         $deleteText = 'and file deletion failed!';
     }
     $article->tags()->detach();
     $article->delete();
     // redirect to the article index
     return Redirect('articles')->with('message', 'Article deleted, ' . $deleteText . '');
 }
Exemplo n.º 29
0
 public function update(Article $article, ArticleRequest $request)
 {
     $article->update($request->all());
     $article->tags()->sync($request->input("tag_list"));
     return redirect('articles');
 }
 private function syncTags(Article $article, $tagList)
 {
     $article->tags()->sync($tagList);
 }