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


PHP Article::save方法代码示例

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


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

示例1: make

 /**
  * Return a fresh instance of the model (called on `create()`).
  *
  * @return \Illuminate\Database\Eloquent\Model
  */
 protected function make()
 {
     $model = new Article();
     $model->publish_date = new Carbon();
     $model->save();
     return $model;
 }
开发者ID:bjrnblm,项目名称:blender,代码行数:12,代码来源:ArticleController.php

示例2: index

 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function index()
 {
     $article = new Article();
     if (Request::isMethod('post')) {
         $rules = ['title' => 'required', 'intro' => 'required', 'content' => 'required'];
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             $messages = $validator->messages();
             return Redirect::to('oszdmeg-te-is')->withErrors($messages)->withInput();
         } else {
             $article = new Article();
             $article->title = Input::get('title');
             $article->intro = Input::get('intro');
             $article->content = Input::get('content');
             $article->display_author_name = Input::get('display_author_name') == 'on' ? Input::get('display_author_name') : 1;
             $article->type_id = 2;
             $article->seo_url = Helpers::seo_url($article->title);
             $article->user = Auth::id();
             $article->save();
             Session::flash('message', 'Köszönjük!.Egyik adminisztrátorunk engedélyezni fogja cikkedet a következő 30 percben.');
             return Redirect::to('/');
         }
     }
     return view('share.index')->with('article', $article);
 }
开发者ID:Thor89,项目名称:horgaszkalandok,代码行数:30,代码来源:ShareController.php

示例3: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(Request $request)
 {
     $this->validate($request, ['title' => 'required|unique:articles|max:255']);
     $article = new Article();
     $article->title = $request->input('title');
     //$post->slug = Str::slug(Input::get('title'));
     $article->cat_id = Input::get('cat_id');
     $article->content = Input::get('content');
     $article->user_id = Auth::user()->id;
     if ($file = Input::file('thumb')) {
         $allowed_extensions = ["png", "jpg", "gif"];
         if ($file->getClientOriginalExtension() && !in_array($file->getClientOriginalExtension(), $allowed_extensions)) {
             return ['error' => 'You may only upload png, jpg or gif.'];
         }
         $fileName = $file->getClientOriginalName();
         $extension = $file->getClientOriginalExtension() ?: 'png';
         $folderName = 'uploads/images/' . date("Ym", time()) . '/' . date("d", time());
         $destinationPath = public_path() . '/' . $folderName;
         $safeName = str_random(10) . '.' . $extension;
         $file->move($destinationPath, $safeName);
         $article->thumb = $folderName . '/' . $safeName;
     }
     if ($article->save()) {
         return Redirect::to('admin/articles');
     } else {
         return Redirect::back()->withInput()->withErrors('保存失败!');
     }
 }
开发者ID:Zachary-Leung,项目名称:wine_platform,代码行数:33,代码来源:ArticlesController.php

示例4: createArticle

 /**
  * Creates and inserts a new article.
  *
  * @param User $user
  * @param $title
  *
  * @return Article
  **/
 public function createArticle(User $user, $title)
 {
     $article = new Article();
     $article->title = $title;
     $article->created_by = $user->id;
     $article->save();
     return $article;
 }
开发者ID:TiagoMaiaL,项目名称:wiki,代码行数:16,代码来源:ArticlesRepository.php

示例5: actionCreate

 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
开发者ID:frankpaul142,项目名称:chaide,代码行数:14,代码来源:ArticleController.php

示例6: actionCreate

 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $this->layout = 'admin';
     $model = new Article();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['browse']);
     } else {
         return $this->render('create', ['model' => $model, 'categories' => ArticleCategory::find()->active()->all()]);
     }
 }
开发者ID:samatic,项目名称:yii2-starter,代码行数:15,代码来源:ArticleController.php

示例7: actionCreate

 /**
  * Creates a new Article model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Article();
     $tourtype = new Tourtype();
     $small = new FileUpload();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'tourtype' => $tourtype, 'small' => $small]);
     }
 }
开发者ID:nguyendtu,项目名称:VietvietTravel,代码行数:16,代码来源:ArticleController.php

示例8: store

 public function store()
 {
     $validation = new ArticleValidator();
     if ($validation->passes()) {
         $article = new Article();
         $article->title = Input::get('title');
         $article->slug = Str::slug(Input::get('title'));
         $article->body = Input::get('body');
         $article->user_id = Sentry::getUser()->id;
         $article->save();
         // Now that we have the article ID we need to move the image
         if (Input::hasFile('image')) {
             $article->image = Image::upload(Input::file('image'), 'articles/' . $article->id);
             $article->save();
         }
         Notification::success('The article was saved.');
         return Redirect::route('admin.articles.edit', $article->id);
     }
     return Redirect::back()->withInput()->withErrors($validation->errors);
 }
开发者ID:daniellimafreire,项目名称:l4-site-tutorial,代码行数:20,代码来源:ArticlesController.php

示例9: store

 public function store(Request $request)
 {
     $user = Auth::user();
     $image = $this->storeFile($request, 'image');
     $data = $request->all();
     $data['image'] = $image ? $image : '';
     $data['author'] = $user->id;
     $article = new Article($data);
     $article->save();
     return redirect('articles/update/' . $article->id);
 }
开发者ID:pjnovas,项目名称:fideicomisos2015,代码行数:11,代码来源:AdminArticles.php

示例10: testSlug

 /**
  * Make sure the slug is made up from the title
  */
 public function testSlug()
 {
     $user = factory(User::class)->create();
     $article = new Article();
     $article->setBody('This is the body');
     $article->setTitle('This is the title');
     $article->user()->associate($user);
     $article->setPublished(Article::PUBLISHED);
     $article->setPublishedAt(Carbon::now());
     $article->save();
     $this->assertEquals('this-is-the-title', $article->slug);
 }
开发者ID:mattvb91,项目名称:website-laravel,代码行数:15,代码来源:ArticleTest.php

示例11: run

 /**
  * composer require fzaninotto/faker
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker\Factory::create();
     Article::truncate();
     for ($i = 0; $i < 100; $i++) {
         $article = new Article();
         $article->title = $faker->sentence;
         $article->excerpt = $faker->text(200);
         $article->content = $faker->text(2000);
         $article->author = $faker->name;
         $article->category_id = $faker->numberBetween(1, count(Category::count()));
         $article->save();
     }
 }
开发者ID:bassx1,项目名称:lessons,代码行数:20,代码来源:CreateArticlesSeed.php

示例12: store

 /**
  * Stores a new article
  *
  * @param Request $request
  * @return $this|\Illuminate\Http\RedirectResponse
  */
 public function store(Request $request)
 {
     // validates the article
     $validation = $this->articlesValidationService->validates($request);
     if ($validation !== true) {
         return redirect('articles/create')->withErrors($validation);
     }
     // stores the article
     $article = new Article();
     $article->title = $request['title'];
     $article->content = $request['content'];
     $article->save();
     return redirect('/')->with('success_message', 'Operação efetuada com sucesso');
 }
开发者ID:GilTSN,项目名称:mvc-sample-app,代码行数:20,代码来源:ArticlesController.php

示例13: store

 public function store()
 {
     $article = new Article();
     $article->user_id = Auth::user()->id;
     $article->title = Input::get('title');
     $article->category_id = Input::get('cate');
     $article->tag = str_replace(',', ',', Input::get('tag'));
     $article->content = Input::get('content');
     $article->ip = \Request::getClientIp();
     $article->created_at = Carbon::now();
     $article->updated_at = Carbon::now();
     if ($article->save()) {
         return Redirect::to('/article/' . $article->id);
     } else {
         return Redirect::back()->withInput()->withErrors('发表失败!');
     }
 }
开发者ID:popohum,项目名称:Earths-Best,代码行数:17,代码来源:ArticleController.php

示例14: actionNew

 public function actionNew()
 {
     if ($this->isPost()) {
         $article = new Article();
         try {
             $article->fill($_POST);
             $article->save();
             $this->redirect('/admin');
         } catch (MultiException $error) {
             $this->view->article = $article;
             $this->view->error = $error;
         }
     } else {
         $this->view->error = false;
     }
     $this->view->display(__DIR__ . '/../../templates/new.php');
 }
开发者ID:AlexPanich,项目名称:php2-dz1,代码行数:17,代码来源:Admin.php

示例15: createArticle

 /**
  * Creates a new User and insert
  * it into the DB.
  *
  * @param User $user
  * @param str $title
  * @param int $count
  *
  * @return array|Article
  */
 public function createArticle(User $user, $title = null, $count = 1)
 {
     $articles = [];
     if (!$title) {
         $title = static::$defaultTitle;
     }
     for ($i = 0; $i < $count; $i++) {
         $article = new Article();
         $articlesCount = count($articles);
         $newTitle = $i > 0 ? $title . $i : $title;
         $article->title = $newTitle;
         $article->created_by = $user->id;
         $article->save();
         $articles[] = $article;
     }
     return count($articles) > 1 ? $articles : $articles[0];
 }
开发者ID:TiagoMaiaL,项目名称:wiki,代码行数:27,代码来源:ArticlesFactory.php


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