Thursday, March 2, 2017

UrlGenerationException in UrlGenerationException.php line 17:

I'm trying to submit a form where when you submit you get taken back to the same page. The problem I'm having is that as far as I know the slug that I'm using will always be unique depending on the story

I'm getting this error

UrlGenerationException in UrlGenerationException.php line 17: Missing required parameters for [Route: slug] [URI: stories/{slug}].

my form

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

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



    
        <input type="hidden" name="comment_id" id="comment_id" value="">
        <div class="form_group">
            
            
        </div>

        <div class="form_group">
            
            
        </div>

        <div class="form_group submit_button">
            
        </div>
    
@stop

My controller function

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('nicole@webkrunch.co.za', Input::get('name'))->subject('A new comment was added');
        });

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

my route

Route::post('/stories/{slug}', [
    'uses' => 'OpenController@comment',
    'as' => 'comment'
]);




via Isis

Advertisement