Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉威尔5.4图像库_Php_Laravel_Laravel 5 - Fatal编程技术网

Php 拉威尔5.4图像库

Php 拉威尔5.4图像库,php,laravel,laravel-5,Php,Laravel,Laravel 5,我正在构建一个Laravel web应用程序,其中我需要一个动态图像库,我构建了一个后端管理面板,可以在其中添加图像,我成功地将图像添加并保存到数据库中,但我无法编辑或删除它们 错误是: UrlGenerationException.php第17行中的ErrorException:Route:galleries.update][URI: 后端/库/{gallery}]。(视图:/var/www/html/tryout101/resources/views/backend/gallery/edit

我正在构建一个Laravel web应用程序,其中我需要一个动态图像库,我构建了一个后端管理面板,可以在其中添加图像,我成功地将图像添加并保存到数据库中,但我无法编辑或删除它们

错误是:

UrlGenerationException.php第17行中的ErrorException:Route:galleries.update][URI: 后端/库/{gallery}]。(视图:/var/www/html/tryout101/resources/views/backend/gallery/edit.blade.php)

这是我的路线代码:

<?php
   /*backend access*/
     Route::group(['prefix' => '/backend'], function() {
     /*The route Dashboard main page */
     Route::get('/' , 'AdminController@index')->name('dashboard');
     Route::resource('galleries' , 'GalleriesController');

     });
      <?php

        namespace App\Http\Controllers;
        use App\Gallery;
        use Illuminate\Http\Request;
        use Image; 
        use Illuminate\Support\Facades\Input;

      class GalleriesController extends Controller
    {
/**
 * Display a listing of the resource.
 *
 * @return \Illuminate\Http\Response
 */
public function index()
{
  $gallery = Gallery::all();
return view('backend.gallery.library', compact('gallery'));
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{
    return view('backend.gallery.uploadform');
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(Request $request)
{
  $gallery = new Gallery();
  $this->validate($request, [
    'title' => 'required',
    'image' => 'required'
  ]);

  $gallery->title = $request->title;
  $gallery->description = $request->description;
  if($request->hasFile('image')) {
    $file = Input::file('image');
    $filename = time(). '-' .$file->getClientOriginalName();
    $gallery->image = $filename;
    $file->move(public_path().'/images/', $filename);
  }
  $gallery->save();
  return $this->create()->with('success', 'Image Uploaded 
  Successfully');
}

/**
 * Display the specified resource.
 *
 * @param  \App\Gallery  $gallery
 * @return \Illuminate\Http\Response
 */
public function show(Gallery $gallery)
{
    //
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  \App\Gallery  $gallery
 * @return \Illuminate\Http\Response
 */
public function edit(Gallery $gallery)
{
    if(!$gallery){
      return redirect('dashboard')->with(['fail'=>'post not found']);
    }
    return view('backend.gallery.edit',compact('gallery'));
}

public function update(Request $request, Gallery $gallery)
{
        $this->validate($request, [
        'title'=>'required|max:120',
        'image'=>'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
       ]);

       $gallery->title = $request->title;
       $gallery->description = $request->description;
         if($request->hasFile('image')) {
         $file = Input::file('image');
         $filename = $file->getClientOriginalName();
         $gallery->image = $filename;
         $file->move(public_path().'images/', $filename);
       }
       $gallery->update();
      return Redirect()->route('dashboard')->with(['success'=> 'post 
      successfully updated']);
   }

    public function destroy(Gallery $gallery)
   {
    //
    }
 }

事实上,“galleries.update”路由需要一个Gallery

因此,在使用该路由调用route函数时,您应该告诉他您要去哪个库

因此,我认为

route('galleries.update')
进入


一切都会好起来的

非常感谢。
route('galleries.update')
route('galleries.update', $gallery)