dqxyh48864 2016-11-03 16:33
浏览 112

Laravel表单模型

My form.blade.php is sth like

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

and my Edit.blade.php is like

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

And this my ProductController.php@edit

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

this is while when i wanna edit a product, the input requests are set empty!! for instance when i go to http://myLarave/Public/product/2/edit the title and other inputs are empty :( any suggestions?!

  • 写回答

1条回答 默认 最新

  • dongzaobei0942 2016-11-03 16:42
    关注

    In your route.php or web.php depend to the version of your laravel, you can make the arg {id?}, for example:

    Route::get('edit/{id?}', 'ProductController@edit');
    

    and in the edit function you can initialize the variable $id=null or empty:

    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);
         }
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)