在空上传文件PDF上调用成员函数getClientOriginalName()

时间:2018-09-11 10:18:55

标签: laravel pdf

我想在控制器中使用laravel上传pdf文件:

 public function store(Request $request)
{
    $categories = Category::findOrFail($request->category_id);
    $request->request->add(['code' => $categories->aliases]);
    $request->validate([
        'code' => 'string',
        'pdf' => 'required',
        'eur' => 'required|numeric',
        'date' => 'required'
    ]);

`

enter code here`$rawInput = $request->except('image');
    $priceInput = $request->only(['idr', 'usd', 'eur', 'date']);
    $pdf = $request->file('pdf')->getClientOriginalName();

在我的剑里...

 <div class="form-group row">
              <label class="col-md-4 col-form-label text-md-right">PDF</label>
              <div class="col-md-6">
                <input type="file" name="pdf" class="form-control{{ $errors->has('pdf') ? ' is-invalid' : '' }}">

                @if ($errors->has('pdf'))
                  <span class="invalid-feedback">
                    <strong>{{ $errors->first('pdf') }}</strong>
                  </span>
                @endif
              </div>
            </div>

当我单击上载时,出现这样的错误

i am getting error undefined varibale $pdf.. $pdf variable i PUT and compact in 

return view('inventory::raws.show', compact(['raw', 'pdf']));

.. 我的代码有什么问题........

1 个答案:

答案 0 :(得分:1)

使用

$pdf = $request->file('pdf')->getClientOriginalName();