/** * 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; }
/** * 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); }
/** * 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('保存失败!'); } }
/** * 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; }
/** * 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]); } }
/** * 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()]); } }
/** * 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]); } }
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); }
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); }
/** * 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); }
/** * 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(); } }
/** * 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'); }
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('发表失败!'); } }
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'); }
/** * 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]; }
/** * 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(); $uploader = new Uploader(); if (Yii::$app->request->isPost) { $uploader->imageFile = UploadedFile::getInstance($uploader, 'imageFile'); $model->user_id = Yii::$app->user->identity->id; $model->date = date("Y-m-d H:i:s"); $model->image_tag = $uploader->imageFile->basename; $model->image_extension = $uploader->imageFile->extension; if ($model->load(Yii::$app->request->post()) && $model->save()) { if ($uploader->upload($model->id)) { return $this->redirect(['view', 'id' => $model->id]); } } } return $this->render('create', ['model' => $model]); }
public function post() { $data = Request::only('slag', 'title'); $data['content'] = htmlentities($_POST['content']); $data['author'] = adminAuth::admin()->name; if (Request::hasFile('article_image')) { $data['image_url'] = upload::upload('asset/article_image/', 'article_image'); } $rules = ['slag' => 'required|max:255', 'author' => 'required|max:255', 'title' => 'required|max:255', 'content' => 'required']; if (validate::make($data, $rules)) { $article = new Article($data); $article->save(); $categories = Request::only('category'); $article->categories()->sync($categories['category']); return Redirect::back()->withResult('operation complete'); } else { return Redirect::back()->withResult('woops!looks like somthing wrong happened'); } }
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()) { Session::flash('notify', ['status' => 'success', 'msg' => 'Article store success!']); return Redirect::to(route('admin.article.index')); } else { Session::flash('notify', ['status' => 'error', 'msg' => 'Article store fail!']); return Redirect::back()->withInput()->withErrors('发布失败!'); } }
/** * 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(); $model->user_id = Yii::$app->user->id; if (Yii::$app->user->can('createArticle', ['model' => $model])) { // Check permission before process acction if ($model->load(Yii::$app->request->post())) { $this->Uploads(false); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { $model->ref = substr(Yii::$app->getSecurity()->generateRandomString(), 10); } return $this->render('create', ['model' => $model]); } else { throw new ForbiddenHttpException('ขอแสดงความเสียใจอย่างสุดซื้ง!, คุณไม่ได้รับอนุญาตให้เข้าใช้งาน'); } /*if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->thumbnail = $model->uploadThumbnail($model,'thumbnail'); $model->photos = $model->uploadMultipleImg($model,'photos'); $model->files = $model->uploadMultipleFiles($model,'files'); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); }*/ /* if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', [ 'model' => $model, ]); } */ }
public function actionForm($id = null) { /** @var Article $model */ if ($id !== null) { $model = Article::findOne($id); if ($model === null) { throw new HttpException(404, 'Document Does Not Exist'); } } else { $model = new Article(); } if (isset($_POST['Article'])) { $model->title = $_POST['Article']['title']; $model->content = $_POST['Article']['content']; if ($model->save()) { Yii::$app->response->redirect(array('article/index')); } } return $this->render('form', ['model' => $model]); }
/** * 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())) { $categories = new ArticleCategories(); $model->psychologist_id = Yii::$app->user->id; $model->is_owner = 1; if ($model->save()) { $articleCategories = Yii::$app->request->post('categories'); if ($categories->saveArticleCategories($model->id, $articleCategories)) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]); } /*if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); }*/ } else { return $this->render('create', ['model' => $model, 'articleCategories' => ArticleCategories::find()->all()]); } }
/** * do add article data to database. */ public function store(Request $request) { $article = new Article(); $input = $request->all(); if ($request->hasFile('featured_img')) { $featured_img = $request->file('featured_img'); if ($featured_img->isValid()) { $ext = '.' . $featured_img->getClientOriginalExtension(); $unique_name = function () { return date('Y_m_d_his_') . strtoupper(uniqid()); }; $new_name = $unique_name() . $ext; try { $featured_img->move(storage_path() . '/app/img/', $new_name); } catch (FileException $e) { Log::error($e->getMessage()); return false; } } } $article->title = $input['title']; $article->author = $input['author']; $article->content = $input['content']; $article->source = $input['source']; $article->category = $input['category']; $article->published_at = date('Y-m-d H:i:s', strtotime($input['published_at'])); $result = $article->save(); if ($result) { return $article->id; } else { if (isset($featured_img)) { unlink(storage_path() . '/app/img/' . $new_name); } } return $result; }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(ArticleRequest $request) { $article = new Article($request->all()); $article->save(); return redirect()->route('admin.articles.index')->with('message', 'Se ha creado ' . $article->name . ' de forma correcta.'); }
/** * Stores an article * @return Response */ public function storeArticle() { $data = Input::all(); $article = new Article(); if ($article->validate($data)) { $file = Input::file('featured'); if ($file != null && $file->isValid()) { $data['featured_img'] = 'articles/' . $article->id . '/' . time() . $file->getClientOriginalName(); $file->move(public_path('files/articles/' . $article->id), $data['featured_img']); } $user = Auth::user(); $article->fill($data); $article->user_id = $user->id; $article->save(); Alert::success('Article created ' . ($article->published ? 'and published' : '') . ' successfully. You may go to menus to link this article to a menu', 'Success'); return Redirect::to('admin/articles')->withSuccess('<strong>Article created successfully.</strong>'); } Input::flash(); return View::make('admin.articles.create')->withErrors($article->getValidator()); }
public function create() { $article = new Article(); if (Request::isMethod('post')) { $rules = array('title' => 'required', 'intro' => 'required', 'content' => 'required', 'type_id' => 'required'); $validator = Validator::make(Input::all(), $rules); // process the login if ($validator->fails()) { return Redirect::to('admin/post/create/')->withErrors($validator)->withInput(); } else { if (empty(Input::get('seo_url'))) { $seo_url = Helper::seo_url(Input::get('title')); } else { $seo_url = $Input::get('seo_url'); } // store $article->title = Input::get('title'); $article->intro = Input::get('intro'); $article->content = Input::get('content'); $article->user_id = Auth::id(); $article->type_id = Input::get('type_id'); $article->display_author_name = Input::get('display_author_name'); $article->seo_url = $seo_url; $article->viewed = 0; $article->status = Input::get('enabled') == 'on' ? 1 : 0; $article->save(); // redirect Session::flash('message', 'New post has been created successfully'); return Redirect::to('/admin/post'); } } $types = ArticleTypes::lists('name', 'id'); return view('admin.post.create')->with(['article' => $article, 'types' => $types]); }
/** * store a resource * @param Request $request http request * @param mixed $id id of the resource for updating * @return jsend jsend with newly stored source */ function store(Request $request, $id = null) { //////////////// // Load Data // //////////////// if ($id) { $data = Model::find($id); if (!$data) { return app()->abort(404); } } else { $data = new Model(); } /////////////////////////////////// // Assign posted data to Data // /////////////////////////////////// $data->fill($request->input()); /////////////////////////////////////////////////////////////////// // Validate data // /////////////////////////////////////////////////////////////////// # Validate User if ($request->input('user_id')) { if (!is_scalar($request->input('user_id'))) { return response()->json(JSend::fail(['user' => ['Invalid User']])->asArray()); } else { $user = User::find($request->input('user_id')); if (!$user) { return response()->json(JSend::fail(['user' => ['Invalid User']])->asArray()); } $data->user_id = $request->input('user_id'); } } /////////////////////////// // Embeds Other Document // /////////////////////////// /////////////////////// // EMBED IMAGES // /////////////////////// foreach ($this->request->input('images') as $x) { $images[] = new Image($x); } if (!$data->syncImages($images)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } /////////////////////// // EMBED TAGS // /////////////////////// foreach ($this->request->input('tags') as $x) { $tags[] = new Tag($x); } if (!$data->syncTags($tags)) { return response()->json(JSend::fail($data->getErrors())->asArray())->setCallback($this->request->input('callback')); } /////////// // Store // /////////// if ($data->save()) { return response()->json(JSend::success(['data' => $data])->asArray()); } else { return response()->json(JSend::fail($data->getErrors())->asArray()); } }
/** * Display the specified resource. * * @param Article $article * @return \Illuminate\Http\Response */ public function show($article) { // Increase views $article->view++; $article->save(); // Output $article->append('first_related_destination')->append('content_as_html'); return View::make('pages.blogdetail', ['article' => $article]); }