本文整理汇总了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']);
}
示例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');
}
示例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');
}
示例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');
}
示例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);
}
示例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]);
}
示例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');
}
示例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());
}
示例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);
}
示例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();
}
示例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');
}
示例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');
}
示例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');
}
示例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');
}
示例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');
}