UrlGenerationException

UrlGenerationException

本文介绍了UrlGenerationException.php第17行中的UrlGenerationException:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试提交一个表单,当您提交表单时,您将被带回到同一页面.我遇到的问题是,据我所知,根据故事的不同,弹头将始终是唯一的

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

我遇到此错误

我的表格

@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' => 'OpenController@comment',
    'as' => 'comment'
]);

推荐答案

我设法做到了.

我改变了

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

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

这篇关于UrlGenerationException.php第17行中的UrlGenerationException:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 16:13