图片上传在laravel 5中不起作用

时间:2016-03-12 08:46:10

标签: laravel laravel-5

我想从管理面板添加一个产品并在larval网站上显示它。对于上面的工作,我跟着。但是在提交表单后它会显示一个空白窗口。有谁能找到这个bug?

ProductController的:

public function store(Request $request)
{
    $image = new Image();
    $this->validate($request, [
        'name' => 'required',
        'price' => 'required'
    ]);
    $image->name = $request->name;
    $image->description = $request->description;
    $image->price = $request->price;
    $image->imageurl = $request->imageurl;

    if($request->hasFile('product_image')) {
        $file = Input::file('product_image');
        //getting timestamp
        $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());

        $name = $timestamp. '-' .$file->getClientOriginalName();

        $image->filePath = $name;

        $file->move(public_path().'/assets/productimage/', $name);
    }
    $image->save();
     return redirect('admin/products');
}

Product.php(模型):

class Product extends Model
{

protected $table ='products';

protected $fillable = [
    'name',
    'description',
    'price',
    'imageurl',
    'product_image'
];

 }

new.blade.php(视图):

        <form class="form-horizontal form-label-left" id="multiple_upload_form" enctype="multipart/form-data" novalidate  action="{{ url('/admin/product/store') }}" method="POST">
              <!-- Redirect browsers with JavaScript disabled to the origin page -->


               <!--  {!! csrf_field() !!} -->
                <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
                <div class="item form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">Product Title*</label>
                  <div class="col-md-6 col-sm-6 col-xs-12">
                  <input id="name" class="form-control col-md-7 col-xs-12" data-validate-length-range="3" name="name" placeholder="Product Title" required="required" type="text" value="" id="name">
                  </div>
                </div>

                <div class="item form-group">
                                        <label class="control-label col-md-3 col-sm-3 col-xs-12" for="textarea">Description <span class="required">*</span>
                                        </label>
                                        <div class="col-md-6 col-sm-6 col-xs-12">
                                            <textarea id="textarea" required="required" class="form-control col-md-7 col-xs-12" placeholder="Description" data-validate-length-range="10" name="description" value=""></textarea>
                                        </div>
                </div>



                 <div class="item form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">Original Price*</label>
                  <div class="col-md-6 col-sm-6 col-xs-12">
                  <input id="price" class="form-control col-md-7 col-xs-12" data-validate-length-range="1" name="price" placeholder="Original Price" required="required" type="number" value="">
                  </div>
                </div>









                <div class="item form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12">Image URL</label>
                  <div class="col-md-6 col-sm-6 col-xs-12">
                  <input id="price" class="form-control col-md-7 col-xs-12" data-validate-length-range="1" name="imageurl" placeholder="Image URL" required="required" type="text" value="">
                  </div>
                </div>

                  <div class="form-group">
                    <label class="col-md-3 control-label" for="file">File</label>
                    <div class="col-md-9">
                        <input id="file" name="product_image" class="input-file" type="file">
                    </div>
                </div>


 <div class="item form-group">
                          <div class="col-md-3"></div>
                          <div class="col-md-2 col-sm-6 col-xs-12">

                                <button class="btn btn-block btn-success" type="submit">Add Product</button>
                            </div>
                             <div class="col-md-2 col-sm-6 col-xs-12">
                                <button class="btn btn-block btn-danger" type="reset">Cancel</button>
                            </div>
              </div>
          </form>

routes.php文件

Route::post('/admin/product/store', 'ProductController@store');

0 个答案:

没有答案