當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。