Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. public function store(Request $request)
  2.     {
  3.         $this->validate($request, [
  4.             'title' => 'required|string',
  5.             'amount' => 'required|numeric',
  6.             'cover' => 'image|mimes:jpg,png,jpeg|max:1024',
  7.             'author_id' => 'required|exists:authors,id',
  8.         ]);
  9.         $books = Book::create($request->except('cover'));
  10.         if ($request->hasFile('cover')) {
  11.             $uploaded_cover = $request->file('cover');
  12.             $extension = $uploaded_cover->getClientOriginalExtension();
  13.             $filename = md5(time()) . '.' . $extension;
  14.             $destinationPath = public_path() . DIRECTORY_SEPARATOR . 'images';
  15.             $uploaded_cover->move($destinationPath, $filename);
  16.             $books->cover = $filename;
  17.             $books->save();
  18.         }
  19.         return redirect()->route('books.index');
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement