该文件必须是Laravel 5.1中类型为:pdf,doc,docx的文件

时间:2015-11-16 06:12:21

标签: laravel-5.1

当我想上传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',
    ];
}

1 个答案:

答案 0 :(得分:0)

回答这个问题(因为这可能使问题得以实现)

$$author

中删除$description

即,将以下代码更改为

$book->$author = $request->input('author');
$book->$description = $request->input('description');
像这样

$book->author = $request->input('author');
$book->description = $request->input('description');

希望,它对未来的读者有所帮助