I'm having a bit of trouble understanding how to pass a variable from one view to another in Laravel.
What I've done is I've made a router that redirects the user to my main page as soon as the user has logged in. Before my controller returns a view, the router creates two objects containing the Customer and Service data linked to the User from the database.
public function index()
{
$customers = Customer::where('CardCode', Auth::user()->customer)->first();
$serviceCalls = ServiceCall::where('customer', Auth::user()->customer)->get();
return view('pages.logged', compact('customers', 'serviceCalls'));
}
After that the view returns to the user showing a Table containing some information from the objects using Blade.
@foreach ($serviceCalls as $serviceCall)
@if ($serviceCall->status != -1)
<tr>
<td><a href="{{ route('service', $serviceCall) }}">{{$serviceCall->subject}}</a></td>
<td>{{$serviceCall->custmrName}}</td>
<td>{{$serviceCall->convertStatusToText($serviceCall->status)}}</td>
</tr>
@endif
@endforeach
As you can see I've tried to create a link out of the first 'td'. In this link I try to pass the current $serviceCall to the router.
Router:
Route::get('/logged/efforts', 'AppController@showServiceCall')->name('service');
AppController function:
public function showServiceCall(ServiceCall $serviceCall)
{
return view('pages.test', compact('serviceCall'));
}
Now the problem I am facing is as follows. Everytime I try and pass a variable within the anchor href tag, the data is passed into the URL. This results in the user being able to manipulate the url to access a different $serviceCall from the database.
What I would like to achieve is being able to pass the variable to 'somewhere' where the user is unable to see/manipulate the input data, and access that variable in the second view.
I have tried to pass the ID as a string and fetch the corresponding object from the Database in the controller before returning the View. But this resulted in the ID showing in the URL and didn't work as visioned. I've tried looking into Sessions but I didn't think that was the right approach.
My experience in PHP and Laravel is very limited so I'm looking for a tip to help me in the right direction. Thank you. (PS. I'm sorry if I have been vague in my description. Many things are new to me coming from C# and Java)