问题描述:

I want to send a value to route that i am received from the controller.!How can i do it.

My controller:

public function payment_history($id)

{

$payment_details=AmountDrvPaidHistoryModel::where('driver_id',$id)->get();

return view('admin.driver_payment_history')->with('payment_details',$payment_details)->with(array('id'=>$id));

}

Here is my blade:

<form action="{{URL::to('driver_payment_history/'.$id)}}" method="post">

How can i get the value of id in action tag that is send to another route.

网友答案:

You code will be:

public function payment_history($id)
{   
    $payment_details = AmountDrvPaidHistoryModel::where('driver_id',$id)->get();

    return view('admin.driver_payment_history', compact('payment_details', 'id'));
}

With compact you can get the variable data, so $id will pass on to the view.

Than you can get the id with this code:

<form action="{{ url('driver_payment_history/'.$id) }}" method="post"> 

EDIT

<form action="{{ url('driver_payment_history/'.$payment_details[0]->driver_id) }}" method="post"> 

Hope this works!

网友答案:

just remove array from this

->with('id'=>$id);
网友答案:

You have to reference the $id inside your function, initiating it to be passed by the specific function.

public function payment_history($id) //<-this is the parameter passed into the function 
{   
    $payment_details=AmountDrvPaidHistoryModel::where('driver_id',$id)->get();
    $new_var_id = $id; //<- Assign the $id to a new variable (eg. $new_var_id)

    return view('admin.driver_payment_history',compact('payment_details','new_var_id');
}

You will then access the variable as such

<form action="{{ url('driver_payment_history/'.$new_var_id) }}" method="post">

However keep in mind that you are already doing a get request with the $id variable, and sending all the results to the page. This means that you can just access the specific id in the view by accessing the objects properties without re initiating the $id variable.

<form action="{{ url('driver_payment_history/'.$payment_details->driver_id) }}" method="post">

If you do use this, you can remove $new_var_id(or whatever you named it) from your controller, as well as removing it from compact()

相关阅读:
Top