Tuesday, March 7, 2017

How to pass the id from a view to a controller to be used as the foreign key in another table?

As the title how to pass id to controller to get related data to that id.

for example

https://i.stack.imgur.com/n1m9v.png

@foreach($persion_data as $person)

  

                    @endforeach

I want to send the id above to the controller to get data from another table!

to make it even clearer

in procedural programming I will do it like this

while($persion = sqlsrv_fetch_array($persion_data ,SQLSRV_FETCH_ASSOC)) 


$id = $persion ['id'];
$customer = "SELECT * FROM [ccl].[customer] WHERE id = '$id' ";

$get_customer_info = sqlsrv_query($conn, $customer);
$get_customer_id = sqlsrv_fetch_array($get_customer_info,SQLSRV_FETCH_ASSOC);

As you see I passed the id to query to get data from another table has relation with the id

how can I do this in laravel ??

I tried to use route but it has to be in url and someone has click it

and it won't work as the example above

how do it, please help



via Ahmadz Issa

Advertisement