當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Article::tags方法代碼示例

本文整理匯總了PHP中app\Article::tags方法的典型用法代碼示例。如果您正苦於以下問題:PHP Article::tags方法的具體用法?PHP Article::tags怎麽用?PHP Article::tags使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Article的用法示例。


在下文中一共展示了Article::tags方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: create

 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']);
 }
開發者ID:otsaan,項目名稱:e-blog,代碼行數:15,代碼來源:ArticleController.php

示例2: update

 /**
  * 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');
 }
開發者ID:belhard-user,項目名稱:group2,代碼行數:14,代碼來源:BlogController.php

示例3: update

 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');
 }
開發者ID:mbrand12,項目名稱:foundation5,代碼行數:7,代碼來源:ArticlesController.php

示例4: store

 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');
 }
開發者ID:tiscomsci29,項目名稱:Laravel_2,代碼行數:30,代碼來源:ArticleController.php

示例5: includeTags

 /**
  * 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);
 }
開發者ID:linuxssm,項目名稱:l5essential,代碼行數:15,代碼來源:ArticleTransformer.php

示例6: update

 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]);
 }
開發者ID:ry-htr,項目名稱:laravel-sample,代碼行數:7,代碼來源:ArticlesController.php

示例7: update

 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');
 }
開發者ID:bartolini69,項目名稱:Laracast-Tutorials,代碼行數:8,代碼來源:ArticlesController.php

示例8: createTestStub

 /**
  * 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());
 }
開發者ID:pokev25,項目名稱:l5essential,代碼行數:14,代碼來源:AuthTest.php

示例9: syncTags

 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);
 }
開發者ID:Arceopteryx,項目名稱:superblog,代碼行數:11,代碼來源:ArticlesController.php

示例10: run

 /**
  * 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();
 }
開發者ID:ganqzz,項目名稱:laracasts-laravel5,代碼行數:23,代碼來源:ArticlesTableSeeder.php

示例11: store

 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');
 }
開發者ID:blitzkriegcoding,項目名稱:blog_cf,代碼行數:19,代碼來源:ArticlesController.php

示例12: store

 /**
  * 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');
 }
開發者ID:rikardote,項目名稱:larablog,代碼行數:25,代碼來源:ArticlesController.php

示例13: store

 /**
  * 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');
 }
開發者ID:EstevenJaviier,項目名稱:Semillero-IN,代碼行數:27,代碼來源:ArticlesController.php

示例14: store

 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');
 }
開發者ID:gratereaux,項目名稱:practicing-laravel,代碼行數:21,代碼來源:ArticlesController.php

示例15: store

 /**
  * 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');
 }
開發者ID:JhonatanC,項目名稱:laravelcodfa,代碼行數:28,代碼來源:ArticlesController.php


注:本文中的app\Article::tags方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。