2016-11-03 5 views
0

form.blade.phpLaravel 양식 모델

<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> ` 

Edit.blade.php 같은 s 번째는

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

처럼 그리고이 내 [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); 
}  

제품을 수정하고 싶을 때 입력 요청이 비어 있습니다! 예를 들어 은 내가 http://myLarave/Public/product/2/edittitle에 갈 때와 다른 입력은 비어있는 :( 제안! 당신의 laravel의 버전에 따라 web.php

답변

0
당신의 route.php에서

또는, 당신은 인수 {id?}을 만들 수 있습니다,

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

및 편집 기능 당신이 null 또는 빈 변수 $ ID = 초기화 할 수 있습니다

:

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

내가 경로를 사용하는 예를 들어, : 'product_path', 'show'=> 'product_path', 'create'=> 'create_product_path', : 리소스는 '제품', 'ProductController', [ '이름' 'edit'=> 'edit_path'], ]); 내 web.php (routes 파일) – Omid

+0

빈 값'' "또는'null'을 사용하여'$ id'를 초기화하고'$ id'가'null' 또는 비어 있지 않으면 모든 동작을 시도 할 수 있습니다. –

+0

실제로'$ id'는 비어 있지 않으며 id를 확인해 주셔서 감사합니다. – Omid