Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel form action parameter

Tags:

php

laravel

I'm trying to call a controller method from a form object, to increment a given item.

The problem is that when adding the parameter, the form action will add a question mark, instead of a slash.

<form method="POST" action="http://localhost/admin/pages?1">

How am I to define the parameter?

{!! Form::open([
    'action'=>['Admin\\PagesController@increment', $item->id],
    'style' => 'display:inline'
]) !!}
    {!! Form::submit('Move Up', ['class' => 'btn btn-danger btn-xs']) !!}
{!! Form::close() !!}
like image 739
Zalon Avatar asked Dec 10 '25 00:12

Zalon


1 Answers

In you code sample, you are sending the item id as a HTTP GET parameter. You can access the item id in your controller by giving a name to the parameter as follows.

{!! Form::open([
    'action'=>['Admin\\PagesController@increment','itemId='.$item->id],
    'style' => 'display:inline'
]) !!}

Then access the item id in your controller by

Input:get('itemId')
like image 89
madawa Avatar answered Dec 12 '25 13:12

madawa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!