2017-04-17 31 views
1

私は動的画像ギャラリーが必要なLaravel Webアプリケーションを構築しています。画像を追加できるバックエンド管理パネルを作成します。画像をデータベースに追加して保存できますが、編集できません。削除してください。Laravel 5.4画像ギャラリー

エラーがある:UrlGenerationException.phpライン17における

ErrorException:[URI: バックエンド/ギャラリー/ {ギャラリー}]:[galleries.updateルート]に必要なパラメータが不足しているが。 (ビュー:/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('/' , '[email protected]')->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) 
    { 
    // 
    } 
} 

/です/

@extends('layouts.backend-master') 
    @section('styles') 
    <link rel="stylesheet" href=""> 
    @endsection 
    @section('content') 
    @if (count($errors) > 0) 
    <div class="alert alert-danger"> 
    <strong>Whoops!</strong> There were some problems with your input. 
    <br><br> 
    <ul> 
     @foreach ($errors->all() as $error) 
     <li>{{ $error }}</li> 
     @endforeach 
    </ul> 
    </div> 
@endif 

<h1>File Upload</h1> 
<form action="{{route('galleries.update')}}" method="post" 
enctype="multipart/form-data"> 

<div class="input-group"> 
    <label for="title">Title</label> 
    <input type="text" name="title" id="title"/> 
</div> 

<div class="input-group"> 
    <label for="description">Description</label> 
    <textarea type="text" name="description" id="description" rows="8"> 
</textarea> 
</div> 

<div class="input-group"> 
    <label for="image">Select image to upload:</label> 
    <input type="file" name="image" id="file"> 
</div> 

<button type="submit" class="btn">Update</button> 
<input type="hidden" name="_token" value="{{Session::token()}}"> 
<input type="hidden" name="gallery" value="{{$gallery->id}}"> 
</form> 
@endsection 
@section('scripts') 
@endsection 

答えて

1

事実は、ルート「galleries.update」は

したがってギャラリーを必要とすることで、あなたはそのルートにルート機能を呼び出すときに行きたいギャラリーを彼に与える必要があり

はこのように、私は

route('galleries.update') 

を変更すると思います

route('galleries.update', $gallery) 

すべてが細かくなります。

+0

ありがとうございました。 –

+0

ようこそ。 –

関連する問題