2016-11-03 6 views
0

Mein form.blade.php ist etw wieLaravel Formular Modell

<div class="form-group"> 
    {!! Form::label('title', 'title :', ['class' => 'awesome']) !!} 
    {!! Form::text('product[title]', null, ['class' => 'form-control']) !!} 
</div> 

<div class="form-group"> 
{!! Form::label('description', 'description : ', ['class' => 'awesome']) !!} 
{!! Form::text('product[description]', null, ['class' => 'form-control']) !!} 

<div id="phone" class="form-group"> 
    {!! Form::label('reference_id1', 'reference_id1 : ', ['class' => 'awesome']) !!} 
    {!! Form::text('product[reference_id1]', null, ['class' => 'form-  control']) !!} 
</div> 

    <div class="form-group"> 
     {!! Form::label('category_id', 'category_id : ', ['class' => 'awesome']) !!} 
     {!! Form::select('category[]', $categories,null, ['class' =>  'form-  control', 'multiple']) !!} 
    </div> 
<div class="form-group"> 
    {!! Form::label('color', 'color : ', ['class' => 'awesome']) !!} 
    {!! Form::text('feature[0][color]', null, ['class' => 'form-control']) !!} 
</div> 
<div class="form-group"> 
    {!! Form::label('height', 'height : ', ['class' => 'awesome']) !!} 
    {!! Form::text('feature[0][height]', null, ['class' => 'form-control']) !!} 
</div> ` 

und meine Edit.blade.php wie

ist
{!! Form::model($product,['method' => 'PATCH', 'action' => ['[email protected]',$product->id]]) !!} 
    @include('products.form', ['submitBtn' => 'submit']) 
{!! Form::close() !!}  

Und das ist mein [email protected]

public function edit($id) 
     { 
     $product = Product::with('feature')->findOrFail($id); 
     $categories = Category::pluck('title','id'); 
     return view('products.edit')->withProduct($product)->withCategories($categories); 
}  

Dies ist, während ich ein Produkt bearbeiten möchte, sind die Eingabeanforderungen leer gesetzt !! zum Beispiel, wenn ich gehe die title und andere Eingänge sind leer :( Anregungen ?!

Antwort

0

In Ihrem route.php oder web.php auf die Version Ihres Laravel abhängen, können Sie die arg {id?} machen, http://myLarave/Public/product/2/edit zum Beispiel:

Route::get('edit/{id?}', '[email protected]'); 

und in der edit-Funktion können Sie die Variable $ id = null oder leer initialisieren:

public function edit($id = null) 
{ 
    if($id != null){ 
     $product = Product::with('feature')->findOrFail($id); 
     $categories = Category::pluck('title','id'); 
     return view('products.edit')->withProduct($product)->withCategories($categories); 
    } 
} 
+0

ich benutze Strecke :: ressource ('product', 'ProductController', [ 'name' => ['index' => 'products_path', 'show' => 'produktpfad', 'create' => 'create_product_path', 'edit' => 'edit_path'], ]); in meiner web.php (routes file) – Omid

+0

Sie können versuchen, nur '$ id' mit dem leeren Wert' "" oder 'null' zu initialisieren und alle Aktionen auszuführen, wenn' $ id' nicht 'null' oder leer ist. –

+0

tatsächlich ist meine '$ ID' nicht leer und vielen Dank für die Überprüfung der ID – Omid