Example #1
0
 public function addDataPost(Request $request)
 {
     $this->validate($request, ['title' => 'required|min:5', 'content' => 'required|min:20', 'images' => 'required']);
     $filename = md5(rand(0, 1000000)) . '.' . $request->file('images')->getClientOriginalExtension();
     if ($request->hasFile('images')) {
         Storage::put($filename, file_get_contents($request->file('images')->getRealPath()));
         Blog::create(['title' => $request->input('title'), 'content' => $request->input('content'), 'category_id' => $request->input('category_id'), 'user_id' => Auth::user()->getId(), 'images' => $filename]);
     }
     return redirect()->route('blog')->with('blog berhasil di tambah');
 }
Example #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param \Illuminate\Http\Request $request
  *
  * @return \Illuminate\Http\Response
  */
 public function store($society, BlogsRequest $request)
 {
     $blog = Blog::create($request->except(array('societies', 'subjects')));
     $blog->societies = implode(',', $request->input('societies'));
     if ($request->input('subjects') != "") {
         $newsubjs = array_map('intval', $request->input('subjects'));
         $blog->subject()->sync($newsubjs);
     }
     $blog->save();
     if ($request->file('blogimage')) {
         $fileName = "blogimage_" . $blog->id . "." . $request->file('blogimage')->getClientOriginalExtension();
         $request->file('blogimage')->move(base_path() . '/storage/app/images/', $fileName);
         $blog->blogimage = '/storage/app/images/' . $fileName;
     }
     $blog->save();
     return redirect(url('/') . '/' . $society . '/blogs')->with('okmessage', 'New blog post has been added');
 }
Example #3
0
 public function postCreate(Request $request)
 {
     Blog::create(['title' => $request->title, 'body' => $request->body, 'user_id' => $request->user()->id]);
     flash()->success('Ви успішно добавили нову статтю');
     return redirect(route('blog'));
 }