dongzhi1822
dongzhi1822
2017-08-13 15:57
浏览 28
已采纳

缺少[Route:ticket.edit] [URI:ticket_ads / edit / {ad}]所需的参数

I am trying to edit a record in a table. I have created a route and the form, but I can't get past this error. I have figured out the problem but I can't find a fix. Am I correct in thinking that the edit.blade.php file needs the $ad->id passing?

The $ad->id is an ID of a specific add in a List View. The list view has all the tickets displayed from a table, and the below link is meant to edit that one item.

The edit route is accessed using following code:

<a href="{{ route('ticket.edit', $ad->id) }}">Edit</a>

I have one route that is supposed to open up the edit view form:

Route::get('/ticket_ads/edit/{ad}', 'TicketAdsController@editTicketAdForm')->name('ticket.edit');

The above route points to this in the controller:

  public function editTicketAdForm($id)
  {
      //$ad = DB::table('ticket_ads')->where('id', $id)->value('id');
      return view('Ads.edit')->with('id', $id);
  }

This is the view called by the above function:

@extends('Shared.Layouts.MasterWithoutMenus')

@section('title')
Edit a ticket ad
@stop

@section('content')
<div class="container">
  <div class="row">
    <div class="col-md-8 col-md-offset-2">
      <div class="panel panel-default">
        <div class="panel-heading"><h2>Edit your ticket ad</h2></div>   <br/>

        @if ($errors->any())
            <div class="alert alert-danger">
                <ul>
                    @foreach ($errors->all() as $error)
                        <li>{{ $error }}</li>
                    @endforeach
                </ul>
            </div>
        @endif

        {{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}

        <div class="form-group">
            {{ Form::label('title', 'Title') }}
            {{ Form::text('title', Input::old('title'), array('class' => 'form-control')) }}
        </div>

        <div class="form-group">
            {{ Form::label('comment', 'Comment') }}
            {{ Form::text('comment', Input::old('comment'), array('class' => 'form-control')) }}
        </div>

        {{ Form::submit('Submit', array('class' => 'btn btn-primary')) }}

        {{ Form::close() }}
      </div>
    </div>
  </div>
 </div>
@endsection

This is the line that throws the error

{{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}

The ID displays normally in the URL as ticket_ads/edit/7 for example.

How do I get past this?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • douzhuang2016
    douzhuang2016 2017-08-13 18:26
    已采纳

    Change this line:

    {{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
    

    to this:

    {{Form::open(array('route' => array('ticket.edit', $id)))}}
    
    点赞 评论
  • doulu4203
    doulu4203 2017-08-13 18:27

    This

    {{ Form::open(array('route' => 'ticket.edit', $id = 'id')) }}
    

    is wrong. Correct syntax is:

    {{ Form::open(['route' => ['ticket.edit', $id]]) }}
    

    also you should safely ditch using array() in favor of [] syntax as Laravel requires PHP 5.4+ anyway (unless you are using ancient version of Laravel, like v4?)

    点赞 评论

相关推荐