Exemple #1
0
 public function store(Request $request)
 {
     $this->validate($request, ['name' => 'required|max:64', 'content' => 'required']);
     $article = new article();
     $article->name = Input::get('name');
     $article->content = Input::get('content');
     $article->user_id = 1;
     return $article->save() ? Redirect::to('/article') : Redirect::back()->withInput()->withErrors('新增失敗!');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     try {
         $article = new article();
         $article->type = Request::get('jenis');
         $article->title = Request::get('judul');
         $article->author = Request::get('author');
         $article->description = Request::get('description');
         $article->keywords = Request::get('keywords');
         $article->tags = Request::get('tags');
         $article->scontent = Request::get('short');
         $article->content = Request::get('content');
         $article->user = Session::get('user')->id;
         $article->save();
     } catch (QueryException $e) {
         return $e->getMessage();
     }
     return Redirect::to('/article');
 }
 public function articleStore(Request $request)
 {
     $art = $request->all();
     $file = $request->file('image');
     $extension = $file->getClientOriginalExtension();
     Storage::disk('local')->put($file->getFilename() . '.' . $extension, File::get($file));
     //article::create($request->all());
     $article = new article();
     $article->id_category = $art['id_category'];
     $article->title = $art['title'];
     $article->desc = $art['desc'];
     $article->content = $art['content'];
     $article->tag = $art['tag'];
     $article->mime = $file->getClientMimeType();
     $article->filename = $file->getFilename() . '.' . $extension;
     $article->original_filename = $file->getClientOriginalName();
     $article->save();
     return redirect('admin/article')->with('message', 'success');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(article $article, Request $request)
 {
     $article->user_id = Auth::user()->id;
     $article->title = $request->title;
     $article->body = $request->body;
     $article->attach = $request->image;
     $article->edit_version = $article->edit_version + 1;
     if ($article->save()) {
         $files = $request->file('attach');
         foreach ($files as $index => $file) {
             if ($file->isValid()) {
                 if ($file->move($this->upload_dir . $article->id . '/', $article->edit_version . $file->getClientOriginalName())) {
                     $attachment = new Attachment();
                     $attachment->article_id = $article->id;
                     $attachment->name = $article->edit_version . $file->getClientOriginalName();
                     $attachment->description = "Dis";
                     $attachment->save();
                     if ($index === 0) {
                         $article->attach = $attachment->name;
                         $article->save();
                     }
                 }
             }
         }
         $request->session()->flash('edited', 'Task was successful!');
     }
     return redirect('articles/' . $article->id . '/edit/');
 }