当前位置: 首页>>代码示例>>PHP>>正文


PHP Article::create方法代码示例

本文整理汇总了PHP中app\Article::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::create方法的具体用法?PHP Article::create怎么用?PHP Article::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Article的用法示例。


在下文中一共展示了Article::create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 10; ++$i) {
         Article::create(['title' => $faker->sentence, 'content' => implode('', $faker->sentences(4))]);
     }
 }
开发者ID:ptaking,项目名称:ptaking.github.io,代码行数:12,代码来源:ArticlesTableSeeder.php

示例2: postPost

 public function postPost(Request $request)
 {
     $input = $request->all();
     $rules = ['title' => ['max:20', 'required'], 'content' => ['min:10', 'required']];
     $validator = Validator::make($input, $rules);
     $returnInf = [];
     if ($validator->fails()) {
         $messages = $validator->messages();
         foreach ($array_dot($messages->toArray) as $value) {
             array_push($returnInf, $value);
         }
         Session::flash('operationResult', 'am-alert-warning');
         Session::flash('returnInf', $returnInf);
         return redirect()->back()->withInput(Request::flash());
     } else {
         $article = Article::create(['title' => $input['title'], 'content' => Common::encodeTopicContent($input['content']), 'node_id' => $input['node_id'], 'user_id' => $input['user_id']]);
         if ($article->id > 0) {
             array_push($returnInf, '发帖成功');
             Session::flash('operationResult', 'am-alert-success');
             Node::find($input['node_id'])->increment('article_count');
             User::find($input['user_id'])->increment('article_count');
         } else {
             array_push($returnInf, '我们的数据库出问题啦,请稍后再试=。=');
             Session::flash('operationResult', 'am-alert-warning');
         }
     }
     Session::flash('returnInf', $returnInf);
     return redirect()->back();
 }
开发者ID:xiaoxielaine,项目名称:hilaravel,代码行数:29,代码来源:UserController.php

示例3: store

 public function store(ArticleFormRequest $request)
 {
     $title = $request->input('title');
     $content = $request->input('content');
     Article::create(['title' => $title, 'content' => $content]);
     return redirect()->route('article.index');
 }
开发者ID:ptaking,项目名称:ptaking.github.io,代码行数:7,代码来源:ArticlesController.php

示例4: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     DB::table('articles')->delete();
     for ($i = 0; $i < 10; $i++) {
         Article::create(['title' => '文章00' . $i, 'slug' => '概述00' . $i, 'body' => '文章00' . $i, 'user_id' => 15]);
     }
 }
开发者ID:swordyt,项目名称:sword,代码行数:12,代码来源:ArticleTableSeeder.php

示例5: store

 /**
  * Function for storing a new blog article.
  *
  * @param $request
  * @param ArticleRequest $request
  * @return Redirect
  */
 public function store(ArticleRequest $request)
 {
     if ($request->has('slug')) {
         $request['slug'] = str_slug($request['slug'], "_");
     } else {
         $request['slug'] = str_slug($request['title'], "_");
     }
     $today = Carbon::today()->format('Y') . '/' . Carbon::today()->format('M') . '/' . Carbon::today()->format('d');
     $uploadPath = base_path() . '/public/img/uploads/' . $today;
     $article = Article::create($request->all());
     // TODO: Refine into two seperate actions //
     if (!empty($request['cover-image']) || !empty($request['cover-image'])) {
         $SmallImageName = '/img/uploads/' . $today . '/' . $request['slug'] . '_sml' . '.' . $request->file('listing-image')->getClientOriginalExtension();
         $coverImageName = '/img/uploads/' . $today . '/' . $request['slug'] . '_cover' . '.' . $request->file('cover-image')->getClientOriginalExtension();
         $article['imgfull'] = $coverImageName;
         $article['imgsml'] = $SmallImageName;
     }
     $article['page_code'] = str_random(16);
     $article['author'] = Auth::user()->id;
     $article['category'] = $request['category'];
     // TODO:: Preform a check to see if this Category Exists //
     $article['published'] = Carbon::parse($request['published']);
     // TODO:: Add a time to publish field //
     $article->save();
     if (!empty($request['cover-image']) || !empty($request['cover-image'])) {
         $request->file('listing-image')->move($uploadPath, $SmallImageName);
         $request->file('cover-image')->move($uploadPath, $coverImageName);
     }
     return redirect('blog/' . $request->slug);
 }
开发者ID:JBird608,项目名称:JoeCurran_Codes,代码行数:37,代码来源:BlogController.php

示例6: store

 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required', 'body' => 'required']);
     $input = $request->all();
     Article::create($input);
     return redirect('articles');
 }
开发者ID:aexpedito,项目名称:laracast,代码行数:7,代码来源:ArticlesController.php

示例7: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $generator = \Faker\Factory::create('vi_VN');
     $articleCategories = ['Thông tin', 'Bài viết nỗi bật'];
     foreach ($articleCategories as $key => $value) {
         $articleCategory = ArticleCategory::create(['key' => Common::createKeyURL($value), 'parent_id' => 0, 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
         ArticleCategoryTranslation::create(['article_category_id' => $articleCategory->id, 'locale' => 'vi', 'name' => $value, 'summary' => $value, 'meta_description' => $value, 'meta_keywords' => $value]);
     }
     $articles = ['Giới thiệu', 'Dịch vụ của chúng tôi', 'Tại sao chọn chúng tôi'];
     foreach ($articles as $key => $item) {
         $article = Article::create(['key' => Common::createKeyURL($item), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
         ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $item, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
         Attachment::create(['entry_id' => $article->id, 'table_name' => 'articles', 'path' => '/uploads/notfound.jpg', 'priority' => 0, 'is_publish' => 1]);
     }
     // BÀI VIẾT THÔNG TIN
     $articleCategory = ArticleCategory::findByKey('thong-tin')->first()->id;
     if (!is_null($articleCategory) && count($articleCategory) > 0) {
         for ($i = 0; $i < 10; $i++) {
             $name = $generator->sentence($nbWords = 6);
             $article = Article::create(['key' => Common::createKeyURL($name), 'priority' => 0, 'is_publish' => 1, 'created_by' => 'phantsang', 'updated_by' => 'phantsang']);
             ArticleTranslation::create(['article_id' => $article->id, 'locale' => 'vi', 'name' => $name, 'summary' => $generator->text($maxNbChars = 200), 'content' => $generator->text, 'meta_description' => $generator->text($maxNbChars = 200), 'meta_keywords' => $generator->text($maxNbChars = 200)]);
             /*
             Attachment::create([
             	'entry_id' => $article->id,
             	'table_name' => 'articles',
             	//'path' => $generator->imageUrl($width = 780, $height = 546),
             	'path' => '/uploads/notfound.jpg',
             	'priority' => 0,
             	'is_publish' => 1
             ]);
             */
             $article->categories()->attach($articleCategory);
         }
     }
 }
开发者ID:phantsang,项目名称:8csfOIjOaJSlDG2Y3x992O,代码行数:40,代码来源:ArticlesTableSeeder.php

示例8: run

 public function run()
 {
     $feeder = Feeder::all()->first();
     $feederId = $feeder->id;
     DB::table('articles')->delete();
     Article::create(array('title' => 'Milano. La stella e le emozioni sono solo Innocenti Evasioni', 'url' => 'http://www.scattidigusto.it/2016/02/12/ristoranti-milano-innocenti-evasioni/', 'feeder_id' => $feederId));
 }
开发者ID:jahnni,项目名称:onamap,代码行数:7,代码来源:DatabaseSeeder.php

示例9: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     for ($i = 0; $i < 20; $i++) {
         Article::create(['title' => $faker->sentence, 'content' => $faker->sentence(20)]);
     }
 }
开发者ID:kevinhoa95,项目名称:myblog,代码行数:12,代码来源:ArticlesTableSeeder.php

示例10: store2

 public function store2(Request $request)
 {
     $this->validate($request, ["body" => "required", "title" => "required|min:3", "published_at" => "required"]);
     $input = $request->all();
     Article::create(["title" => $input->title, "body" => $input->body, "published_at" => $input->published_at]);
     return redirect("articles");
 }
开发者ID:Aetheus,项目名称:tutorials-and-exercises,代码行数:7,代码来源:ArticlesController.php

示例11: store

 public function store(ArticleRequest $request)
 {
     $article = Article::create($request->all());
     $article->tags()->attach($request->input('tag_list'));
     flash()->success("Your article has been created");
     return redirect('articles');
 }
开发者ID:mbrand12,项目名称:foundation5,代码行数:7,代码来源:ArticlesController.php

示例12: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = Request::all();
     Article::create($input);
     //denne metoden lagrer i databasen
     return redirect('articles');
 }
开发者ID:kieung,项目名称:Laravel,代码行数:12,代码来源:ArticlesController.php

示例13: create

 /**
  * article store.
  *
  * @return \Illuminate\Http\Response
  */
 public function create(Request $request)
 {
     $data = $request->all();
     // dd($data);
     Article::create($data);
     return response()->json(['message' => '添加成功'], 201);
 }
开发者ID:lavenkin,项目名称:bugblog,代码行数:12,代码来源:ArticleController.php

示例14: store

 public function store(ArticleFormRequest $request)
 {
     $title = $request->input('title');
     $content = $request->input('content');
     Article::create(['title' => $title, 'content' => $content, 'username' => auth()->user()->name]);
     return redirect()->route('get.articles');
 }
开发者ID:kevinhoa95,项目名称:myblog,代码行数:7,代码来源:ArticlesController.php

示例15: run

 public function run()
 {
     DB::table('articles')->delete();
     for ($i = 0; $i < 10; $i++) {
         Article::create(['title' => 'Title ' . $i, 'slug' => 'first-page', 'body' => 'Body ' . $i, 'body' => 'Body ' . $i, 'image' => 'image ' . $i, 'user_id' => 1]);
     }
 }
开发者ID:jsRuner,项目名称:learnlar,代码行数:7,代码来源:ArticleTableSeeder.php


注:本文中的app\Article::create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。