2017-03-02 61 views
1

我正在嘗試提交表單,當您提交時,您會收回相同的頁面。我遇到的問題是,據我知道,我使用的將永遠是唯一取決於故事UrlGenerationException.php中的UrlGenerationException第17行:

我得到這個錯誤

UrlGenerationException在UrlGenerationException.php線蛞蝓17:缺少[Route:slug] [URI:stories/{slug}]所需的參數。

我的形式

@extends('templates::layouts.public') 

@section('content') 
    @foreach($stories as $story) 
     {!! $story->title !!} 
     {!! $story->content !!} 
    @endforeach 



    {{ Form::open(array('url' => '/stories/'.$slug, 'id' => 'comment_form')) }} 
     <input type="hidden" name="comment_id" id="comment_id" value=""> 
     <div class="form_group"> 
      {{ Form::label('name', 'Name') }} 
      {{ Form::text('name', '' , array("class" => "form-control")) }} 
     </div> 

     <div class="form_group"> 
      {{ Form::label('comment', 'Comment') }} 
      {{ Form::textarea('comment', '' , array("class" => "form-control")) }} 
     </div> 

     <div class="form_group submit_button"> 
      {{ Form::submit('Submit', array("class" =>"btn btn-info submit", "role" => "button")) }} 
     </div> 
    {{ Form::close() }} 
@stop 

我的控制器功能

public function comment(Request $request, $slug) 
{ 

    $comments = new Comment(); 

    $input = Input::all(); 

    $validation = Validator::make($input, Comment::$rules); 

    if($validation->fails()) 
    { 
     return redirect()->route('') 
         ->withInput() 
         ->withErrors($validation) 
         ->with('message', 'There were validation errors'); 
    } 

    if($validation->passes()) 
    { 
     $comments->name = Input::get('name'); 
     $comments->comment = Input::get('comment'); 

     $data = array(
        'name' => Input::get('name'), 
        'comment' => Input::get('comment') 
       ); 

     Mail::send('templates::emails.comment', $data, function($message){ 
      $message->to('[email protected]', Input::get('name'))->subject('A new comment was added'); 
     }); 

     $comments->save(); 
     $comments = Comment::all(); 
     return redirect()->route('slug'); 
    } 
} 

我的路線

Route::post('/stories/{slug}', [ 
    'uses' => '[email protected]', 
    'as' => 'comment' 
]); 
+0

那麼,錯誤是很清楚的:你沒有正確地建立自己的路線。去這裏https://laravel.com/docs/5.4/routing,並學習如何正確地做到這一點。 – Amarnasan

+0

從哪裏得到slu form的形狀? –

回答

0

我設法做到這一點。

我改變

return redirect()->route('slug'); 

return view('open::public.single-story', compact('menus_child', 'stories', 'slug')); 
相關問題