Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function store(Request $request)
- {
- $this->validate($request, [
- 'title' => 'required|string',
- 'amount' => 'required|numeric',
- 'cover' => 'image|mimes:jpg,png,jpeg|max:1024',
- 'author_id' => 'required|exists:authors,id',
- ]);
- $books = Book::create($request->except('cover'));
- if ($request->hasFile('cover')) {
- $uploaded_cover = $request->file('cover');
- $extension = $uploaded_cover->getClientOriginalExtension();
- $filename = md5(time()) . '.' . $extension;
- $destinationPath = public_path() . DIRECTORY_SEPARATOR . 'images';
- $uploaded_cover->move($destinationPath, $filename);
- $books->cover = $filename;
- $books->save();
- }
- return redirect()->route('books.index');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement