drwu24647 2016-10-12 11:46
浏览 28

Laravel雄辩列出了更新

In my update function the generated dropdown list of categories is always set to the first one pulled from the database.

Given a list 1,2,3. Current article has a categorie 2. And you want to update it, categorie is set to 1 in update page.

I want this to remain the current value in the database if nothing is changed. I've tried to prepend to the lists array but without succes.

This is the code:

1) Part of update function

    $data['post'] = Blog::where('slug', $slug)->first();

    //Getting the current article category ID
    $currentCat = $data['post']->category;

    //Getting the current article category name
    $currentCatName = $data['post']->categoryy->name;

    $data['categories'] = [$currentCatName => $currentCat] + BlogCategories::orderBy('name', 'asc')->lists('name', 'id');

    return view('admin.blog.edit', $data);

2) Update view

{!! Form::open(['url' => 'admin/blogbeheer/update/'.$post->id.'', 'files' => true]) !!}
  <div class="form-group">
  {!! Form::label('title', 'Titel: ') !!}
  {!! Form::text('title', $post->title, ['class' => 'form-control', 'maxlength' => '255']) !!}
  </div>

  <!-- form input -->
  <div class="form-group">
  {!! Form::label('Body', 'Body: ') !!}
  {!! Form::textarea('body', $post->blog_text, ['class' => 'form-control', 'id' => 'body']) !!}
  </div>

  <div class="form-group">
  {!! Form::label('category', 'Kies een categorie: ') !!}
  {!! Form::select('category', $categories) !!}
  </div>

  <div class="form-group">
  <img src="../../../{{ $post->img }}" width="400px">
  </div>

  <!-- form input -->
  <div class="form-group">
  {!! Form::label('picture', 'Afbeelding: ') !!}
  {!! Form::file('picture', null, ['class' => 'form-control']) !!}
  </div>



  <!-- Form input -->
  <div class="form-group">
  {!! Form::submit('Bewaar', ['class' => 'btn btn-primary form-control']) !!}
  </div>

{!! Form::close() !!}
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信小程序协议怎么写
    • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
    • ¥20 怎么用dlib库的算法识别小麦病虫害
    • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
    • ¥15 java写代码遇到问题,求帮助
    • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
    • ¥15 有了解d3和topogram.js库的吗?有偿请教
    • ¥100 任意维数的K均值聚类
    • ¥15 stamps做sbas-insar,时序沉降图怎么画
    • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看