epowah epowah - 1 year ago 95
PHP Question

Sending more than one arguments in the action Laravel

I want to ask can i send more than one arguments in action tag, for example can i send two id arguments, something like this

<a href="{{ route('product.makeOrder',['id' => $order->id]),here I want to send Auth::user()->id }}" name="req" class="btn btn-warning">Order this product!</a>

Is that possible?

Answer Source

You don't need to send Auth::user() object since it's global object and you can get it both in model and controller.

If for some reason you still want to send it, you can use hidden inputs for that:

{!! Form::open(['route' => 'data.store']) !!}
{!! Form::hidden('user_id', auth()->user()->id) !!}
{!! Form::submit('Submit') !!}
{!! Form::close() !!}

And then get it in a controller:

public function store(Request $request)
    $userId = $request->user_id;

This way is good when you want to send multiple parameters and big data parameters like arrays or JSON.

If you want to use simple GET, you can do this:

<a href="{{ url('make-order/'.$order->id.'/'.auth()->user()->id) }}">Send parameters</a>

And set route as:

Route::get('make-order/{id}/{userId}', 'SomeController@makeOrder');

Then get data in a controller:

public function makeOrder($id, $userId)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download