2015-09-27 31 views
0

下面是從我的產品視圖的代碼:系列化的「閉合不允許」錯誤

{{ Form::open(array('url'=>'admin/products/create' , 'files'=>true)) }} 
      <p> 
      {{ Form::label('category_id' , 'Category') }} 
      {{ Form::select('category_id' , $categories) }} 
      </p> 
      <p> 
      {{ Form::label('title') }} 
      {{ Form::text('title') }} 
      </p> 
      <p> 
      {{ Form::label('description') }} 
      {{ Form::textarea('description') }} 
      </p> 
      <p> 
      {{ Form::label('height') }} 
      {{ Form::text('height' , null , array('class'=>'form-price')) }} 
      </p> 
      <p> 
       {{ Form::label('width') }} 
       {{ Form::text('width' , null , array('class'=>'form-price')) }} 
      <!--{{ Form::label('image' , 'Choose an image') }} 
      {{ Form::file('image') }}--> 
      </p> 
      <p> 
       {{ Form::label('length') }} 
       {{ Form::text('length' , null , array('class'=>'form-price')) }} 
      </p> 
      <p> 
       {{ Form::label('color') }} 
       {{ Form::text('color' , null , array('class'=>'form-price')) }} 
      </p> 
      <p> 
       {{ Form::label('material') }} 
       {{ Form::text('material' , null , array('class'=>'form-price')) }} 
      </p> 
      {{ Form::submit('Create Product' , array('class'=>'secondary-cart-btn')) }} 
      {{ Form::close() }} 

和下面是從我的產品控制器的代碼:

<?php 

/** 
* 
*/ 
class ProductsController extends BaseController { 

    public function __construct() { 
    $this->beforeFilter('csrf' , array('on'=>'post')); 
    } 

    public function getIndex() { 


    /* NOTE :: the categories array is being 
    created so that the products index page 
    can have access to all the availability 
    categories */ 

    $categories = array(); 

    foreach (Category::all() as $category) { 
     $categories[$category->id] = $category->name; 
    } 

     return View::make('products.index') 
     ->with('products' , Product::all()) 
     ->with('categories' , $categories); 

    } 

    public function postCreate() { 

    $validator = Validator::make(Input::all() , Product::$rules); 

    if($validator->passes()) { 
     $product = new Product; 

     $product->category_id = Input::get('category_id'); 
     $product->title = Input::get('title'); 
     $product->description = Input::get('description'); 
     $product->height = Input::get('height'); 
     $product->width = Input::get('width'); 
     $product->length = Input::get('length'); 
     $product->color = Input::get('color'); 
     $product->material = Input::get('material'); 


     /* code for saving the image */ 
    /* $image = Input::file('image'); 
     $filename = date('Y-m-d-H-i-s')."-".$image->getClientOriginalName(); 
     $path = public_path('img/products/' .$filename); 
     Image::make($image->getRealPath())->resize(468, 249)->save($path); 
     $product->image = 'img/products/'.$filename; */ 
     /*end of code for saving the image */ 

     $product->save(); 

     return Redirect::to('admin/products/index') 
     ->with('message' , 'Product created'); 
    } 

    return Redirect::to('admin/products/index') 
     ->with('message' , 'something went wrong') 
     ->withError($validator) 
     ->withInput(); 
    } 

    public function postDestroy() { 

     $product = Product::find(Input::get('id')); 
     if ($product) { 
     $product->delete(); 
     return Redirect::to('admin/products/index') 
     ->with('message' , 'product has been deleted'); 
     } 

     return Redirect::to('admin/products/index') 
     ->with('message' , 'something went wrong , Please try again'); 
    } 
} 
?> 

現在,當我填補值在形式和點擊提交,我得到一個錯誤,如下所示:

Error image

系列化的「封不準」,在谷歌上搜索了一下,我發現下面的有用線索:

Related thread

接受的解決方案並不適用於我,我試圖解決的第二個答案,我仍然有同樣的錯誤。

我仍然不明白可能是這個錯誤的原因或我做錯了什麼?有人可以解釋嗎?

回答

1

除非它是您發佈的代碼中的拼寫錯誤,否則您發佈的相關問題的接受解決方案與您有關。

在您的退貨聲明中,您有->withError($validator),這應該是->withErrors($validator)(您錯過了's')。

相關問題