I want to fetch data from my database but I am stuck when I try to get data from another table.
This is what I want to do, when a user login to the web page, he would be able to see a list of people name. By clicking on their name, user will be redirected to another page which will show the person details such as name, address and email. But because there is so many of them (assuming around 200 people)
Questions:
Q1. how do I redirect the user to another page which is the name (eg: jack, user click on jack name, jack id = 1, how do I relate it back to the user_id = 1 which is the foreign key)
Q2. how do I do a loop to get their information instead of specifying it 1 by 1 (eg: I don't want to keep saying id=1, is there something like id++ which will help auto add)
This is how it looks like with my code: (picture I took from the internet but it something similar to this)

home.blade.php
<table class="table table-bordered">
<tr>
<th><strong><big>Name AS PER NRIC/PASSPORT: </big></strong></th>
</tr>
<td>
<tr>
@foreach($data as $value)
<tr>
<th><a href="www.google.com"> {{$value->Name}}</a></th> --> I don't know how to redirect it to show user details
</tr>
@endforeach
</tr>
</tr>
</table>
Controller
public function index()
{
return view('home');
}
public function getData(){
$data['data'] = DB::table('personal_infos')->get()->sortByDesc('upload_time');
if(count($data)>0){
return view('home',$data);
}else{
return view('home');
}
}
}
Route
Route::get('/test','testController@getData');
personal_info model
class personal_info extends Eloquent
{
protected $fillable = array('Email', 'Name', 'address');
protected $table = 'personal_infos';
protected $primaryKey = 'id';
public function user_infos() {
return $this->hasMany('App\user_info,'user_id');
}
public function user_info1s() {
return $this->hasMany('App\user_info1','user_id');
}
}
user_info and user_info1 model
class user_info1 extends Eloquent
{
protected $fillable = array('hobby','sport','user_id');
public function personal_infos() {
return $this->belongsTo('App\personal_info', 'user_id', 'id');
}
personal_infos::with('user_info1s')->get()? - madalinivascu