当我想上传pdf或ms word文件时,我收到此错误:
该文件必须是以下类型的文件:pdf,doc,docx
这是我的控制者:
public function store(BookRequest $request)
{
$book = new Book();
$book->title = $request->input('title');
$book->isbn = $request->input('isbn');
$book->$author = $request->input('author');
$book->$description = $request->input('description');
if($request->hasFile('file'))
{
$file = $request->file('file');
$fileName = date('Y') . "_" . $file->getClientOriginalName();
$distination_path = 'books/';
$file->move($distination_path, $fileName);
$book->book_path = $distination_path . $fileName;
}
$book->user_id = \Auth::user()->id;
$book->save();
return redirect('/library')->with('message','کتاب موفقانه آپلود شد.')->withErrors('مشکل رخداد');
}
请求:
public function rules()
{
return [
'title'=>'required',
'author'=>'required',
'isbn'=>'required',
'file'=>'required|mimes:pdf,doc,docx',
];
}
答案 0 :(得分:0)
回答这个问题(因为这可能使问题得以实现)
从$
和$author
$description
即,将以下代码更改为
$book->$author = $request->input('author');
$book->$description = $request->input('description');
像这样
$book->author = $request->input('author');
$book->description = $request->input('description');
希望,它对未来的读者有所帮助