Reputation: 117
I am trying to get the data from two different tables and display it on one page, i means at one view. But only one function working on same time while the other not and vice versa, Both the functions work seperately but not combinely. Please help. my code is give. PdfContoller.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use DB;
use PDF;
use Auth;
class PdfController extends Controller
{
public function personalpdf()
{
if(\Auth::check()){
$user = \Auth::user();
return view('pdf/personalpdf',compact('user'));
}
else
{
return view('pdf/personalpdf');
}
}
public function personalphd()
{
$user_id = Auth::user()->id;
$result['result'] = DB::table('education')->where('user_id' ,'=', $user_id)->get();
if(count ($result)>0){
return view('pdf/personalpdf',$result);
}
else
{
return view('pdf/personalpdf');
}
}
}
My controller contains the above two functions for fetching data from two different tables. My view file is personalpdf.blade.php is given here.
@extends('layouts.app')
@section('content')
<div class="container"><br>
<h1 class="text-success text-center">Profile</h1><br>
<table class="table table-bordered">
@if(isset($user))
<tr>
<th>Name</th>
<td>{{ $user ->tname}}</td>
</tr>
<tr>
<th>Father Name</th>
<td>{{ $user ->fname}}</td>
</tr>
<tr>
<th>Contact Number</th>
<td>{{ $user ->phone}}</td>
</tr>
<tr>
<th>Email</th>
<td>{{ $user ->email}}</td>
</tr>
<tr>
<th>Official Email</th>
<td>{{ $user ->off_email}}</td>
</tr>
@endif
</table>
<div class="text text-success text-center">
PHD Research
</div>
<table class="table">
<tr>
<th>
PHD Research Area
</th>
<th>University</th>
<th>Country</th>
</tr>
@foreach($result as $value)
<tr>
<td>{{$value->research_area}}</td>
<td>{{$value->univ}}</td>
<td>{{$value->country}}</td>
</tr>
@endforeach
</table>
@endsection
My routes is given here.
Route::get('pdf/personalpdf','PdfController@personalpdf');
Route::get('pdf/personalpdf','PdfController@personalphd');
Route::get('/personal','PdfController@personal');
Actually I want to make a view file where I can see all the personal details of current login user. And below it I want to display his PHD research details getting from education table. But I am getting only one result on a same time. I means if I got personal detail of login user then phd detail not showing, if I get phd details it gives me all the phd details, not of current login user. Please help.
Upvotes: 0
Views: 388
Reputation: 233
class PdfController extends Controller
{
public function personalpdf()
{
if(\Auth::check()){
$user = \Auth::user();
$user_id = $user->id;
$result = DB::table('education')->where('user_id' ,'=', $user_id)->get();
return view('pdf/personalpdf',compact('user', 'result'));
}else {
return view('pdf/personalpdf');
}
}
}
Routes file
Route::get('pdf/personalpdf','PdfController@personalpdf');
Route::get('/personal','PdfController@personal');
Try this. You have to pass both the user and results from the same controller action to the view. I think you lack some basics of laravel. Please go through the docs before you proceed.
Upvotes: 1