Two things you should keep in mind :
- You do not call data from one controller to another.
- You need not to create different controller for every thing for one entity. To be very clear all the process regarding a vendor should go into one single VendorController if you want to divide the job to make the controller small use classes,Models and Repositories(for DB interaction) and may be helpers.
So, back to your question, you want to display the data of this vendor upon button click(dynamically). Then you should make use of jquery, I am adding small code snippet for the same :
make a new route in route.php(for Laravel 5.2 and earlier) or web.php(for Laravel 5.3)
Route::get('vendor-address/{id}', 'VendorController@getAddress');
create a js file lets call it custom.js and place it in your public or resources folder, lets keep it in public for the time being. Content of the same :
$('#show-address').click(function()
{
//get the id of the vendor we want to fetch address of
var vendor_id = $(this).data('id');
//send a get request to our controller to get the data
$.get('/vendor-address/'+vendor_id, function(data)
{
//store the json data we got from the controller into a variable
var parsed = JSON.parse(data);
//remove all the content of this vendors address div so that the address doesn't repeats
$('.vendor_address_'+vendor_id).empty();
//append the address in this div
$('.vendor_address_'+vendor_id).append(parsed);
});
})
now in your view you should have :
<button class="btn btn-success" data-id="{{$vendor->id}}">Show address</button>
//and a empty div, our address will be appended here
<div class="vendor_address_{{$vendor->id}}"></div>
now in your controller :
public function getAddress($id)
{
$address = Vendor::where('id', $id)->first();
return json_encode($address->address);
}
Please modify few fields according to your requirement