将PDF文件保存到数据库和公用文件夹

时间:2019-01-14 06:26:39

标签: php laravel laravel-blade

控制器

public function edit(Request $request)
{
    $this->validate($request, [
        'title_journal' => 'required',
        'content' => 'required|mimes:pdf,doc,docx|max:10240',
        'contenttitle' => 'required',
    ]);

    if ($request->hasFile('content')) {
        $pdf = $request->file('content');
        $name = $pdf->getClientOriginalName();
        $destinationPath = ('pdf/');
        $pdf->move($destinationPath, $name);

        $newcontent = new CurrentIssue;
        $newcontent->content = ('pdf/') . $name;
        $newcontent->title_journal = $request->input('title_journal');
        $newcontent->content_title = $request->input('contenttitle');
        $newcontent->save();

        return redirect('/currentissue')->with('success', 'New Content Added');
    }
}

查看

{!! Form::open(['action' => ['CurrentIssueController@edit', 
    $currentissue->id], 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
@csrf
{{ Form::hidden('title_journal', $currentissue->title) }}
<div class="form-group row">
    {{Form::label('contenttitle', 'Table of Content Title', ['class' => 'col-md-3 col-form-label text-md-right'])}}
    <div class="col-md-6">
        {{Form::text('contenttitle', '', ['class' => 'form-control'])}}
    </div>
</div>

<div class="form-group row">
    {{Form::label('content', 'Content PDF', ['class' => 'col-md-3 col-form-label text-md-right'])}}
    <div class="col-md-6">
        {{Form::file('content', array('url' => '/public/pdf','files'=>'true'))}}
    </div>
</div>

<div class="form-group row mb-0">
    <div class="col-md-6 offset-md-3">
        <button type="submit" class="button button1">
            Save
        </button>
    </div>
</div>
{!! Form::close() !!}

错误

  

Symfony \组件\ HttpKernel \ Exception \ MethodNotAllowedHttpException

没有消息

error

0 个答案:

没有答案