图像未显示在编辑刀片中

时间:2019-07-29 03:13:13

标签: laravel eloquent laravel-5.8

尝试编辑数据,但在edit.blade.php上,所有数据均未显示,包括图像,仅显示category_name值,如何解决该问题?、、、、、、、、、、、、 ,,,,,,,,,,,,,,都不显示所有数据,包括图像,仅显示category_name值

edit.blade.php:

    <form method="POST" action="{{ route('admin.category.update', $categories->id) }}" enctype="multipart/form-data">
                    @csrf
                    @method('PATCH')
                    <strong class="text-muted d-block mb-2">Category Name</strong>
                    <div class="input-group mb-3">
                      <div class="input-group input-group-seamless">
                        <input type="text" name="category_name" class="form-control @error('category_name') is-invalid @enderror" value="{{ $categories->category_name }}" id="">
                      </div>
                      @error('category_name')
                        <div class="small text-danger">{{ $message }}</div>
                      @enderror
                    </div>
                    <strong class="text-muted d-block mb-2">Description</strong>
                    <div class="input-group mb-3">
                      <div class="input-group input-group-seamless">
                        <textarea name="category_description" class="form-control @error('category_description') is-invalid @enderror" value="{{ $categories->category_description }}"></textarea>
                      </div>
                      @error('category_description')
                        <div class="small text-danger">{{ $message }}</div>
                      @enderror
                    </div>
                    <strong class="text-muted d-block mb-2">Slug</strong>
                    <div class="input-group mb-3">
                      <div class="input-group input-group-seamless">
                        <input type="text" name="category_slug" class="form-control @error('category_slug') is-invalid @enderror" value="{{ $categories->category_slug }}"> </div>
                        @error('category_slug')
                          <div class="small text-danger">{{ $message }}</div>
                        @enderror
                    </div>
                    <div class="input-group mb-3">
                      <div class="input-group input-group-seamless">
                         <input type="file" name="category_image" class="form-control mb-2 btn btn-sm btn-outline-primary mr-1 @error('category_image') is-invalid @enderror" value="{{ $categories->category_image }}">
                      </div>
                         @error('category_image')
                          <div class="small text-danger">{{ $message }}</div>
                        @enderror
                        <img src="{{ URL::to('/') }}/images/{{ $categories->category_image }}" class="img-thumbnail" width="100" />
                         <input type="hidden" name="hidden_image" value="{{ $categories->category_image }}" />
                    </div>
                    <button type="submit" class="mb-2 btn btn-primary mr-2">Edit Category</button>
                  </form>

控制器:

  public function edit(Category $category)
  {
    $categories = Category::findOrFail($category->id);
    return view('admin.category.edit', compact('categories'));
  }

1 个答案:

答案 0 :(得分:0)

如果您使用的是资源控制器,那么您的编辑功能应如下所示:

 public function edit(Category $category)
 {
     return view('admin.category.edit', compact('category'));
 }

您两次运行相同的查询。 另外,请确保您使用的是资源路由:

 Route::resource('category', 'CategoryController');

请参见Laravel Docs