1

lets assume we have a Delete button inside a form :

 {!! Form::open(['route' => ['posts.destroy','id'=>$post->id], 'method' => 'delete']) !!}
 {!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
 {!! Form::close() !!}

i need to pass two or more variables through the Form Route like this:

{!! Form::open(['route' => ['posts.destroy','id'=>$post->id,'title'=>$post->title], 'method' => 'delete']) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}

I try to different ways , to take these two parameters but still I couldn't retrieve data

ErrorException in PostController.php line 99:
Missing argument 2 for App\Http\Controllers\PostController::destroy()
Mohammed Ali
  • 1,117
  • 1
  • 16
  • 31
  • The arguments to the controller method are route parameters. Your route would need to be defined to take the extra parameters for them to be passed to your controller method ... how have you defined that route? – lagbox Apr 26 '20 at 14:25
  • @lagbox through the default resource route that give index,edit,delete....extra – Mohammed Ali Apr 26 '20 at 14:30
  • the error is because there is a missing parameter to the controller method because you have it defined taking more arguments then will actually be passed (there is only 1 route parameter that the route defines, not 2) [assuming you are not using dependency injection there] ... you should show the method signature for that controller method ... query data or post data is not passed to the controller as arguments – lagbox Apr 26 '20 at 14:33
  • "query data or post data is not passed to the controller as arguments ": i tried $post->id,$post->title as examples of input not as query results! – Mohammed Ali Apr 26 '20 at 14:38
  • show the method signature, you have 2 arguments defined for the method, but only 1 parameter will be passed because there is only 1 route parameter defined (most likely) – lagbox Apr 26 '20 at 14:39

0 Answers0