本文整理汇总了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;
}
示例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);
}
示例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('保存失败!');
}
}
示例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;
}
示例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]);
}
}
示例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()]);
}
}
示例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]);
}
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
}
示例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');
}
示例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('发表失败!');
}
}
示例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');
}
示例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];
}