I had used a custom query in my controller in laravel here is my code in my controller:
public function c_viewSystemUser()
{
$title = "View System Users";
$jSu = DB::select(DB::raw("SELECT dbo_systemusers.SystemUserID,dbo_systemtypes.SystemType, dbo_systemusers.SystemUserName INNER JOIN dbo_systemtypes ON dbo_systemusers.SystemUserTypeID = dbo_systemtypes.SystemUserTypeID"));
return View::make('ssims.view_systemUser',compact('title','jSu'));
}
I wanted to display its result in my blade file view_systemUser
here is my code inside the view:
#if ($jSu)
<table class="table table-striped table-hover" id="detailTable">
<thead>
<tr>
<th>System User ID</th>
<th>SystemUser Type ID</th>
<th>System UserName</th>
<th>System User Description</th>
</tr>
</thead>
<tbody>
#foreach ($jSu as $vu)
<tr>
<td>{{ $vu->dbo_systemusers.SystemUserID }}</td>
<td>{{ $vu->dbo_systemtypes.SystemType }}</td>
<td>{{ $vu->dbo_systemusers.SystemUserName}}</td>
<td>{{ $vu->dbo_systemusers.SystemUserDescription}}</td>
</tr>
#endforeach
</tbody>
</table>
And I am having an error:
Undefined property: stdClass::$dbo_systemusers (View:
C:\xampp\htdocs\laravel3\app\views\ssims\view_systemUser.blade.php)
Any suggestions?
Try this:
#foreach ($jSu as $key => $vu)
<tr>
<td>{{ $vu->SystemUserID }}</td>
<td>{{ $vu->SystemType }}</td>
<td>{{ $vu->SystemUserName}}</td>
<td>{{ $vu->SystemUserDescription}}</td>
</tr>
#endforeach
You forgot to join dbo_systemusers with dbo_systemtypes.
Try this code
SELECT dbo_systemusers.SystemUserID,dbo_systemtypes.SystemType, dbo_systemusers.SystemUserName from dbo_systemusers INNER JOIN dbo_systemtypes ON dbo_systemusers.SystemUserTypeID = dbo_systemtypes.SystemUserTypeID
And Try this on View page
#foreach ($jSu as $vu)
<tr>
<td>{{ $vu->SystemUserID }}</td>
<td>{{ $vu->SystemType }}</td>
<td>{{ $vu->SystemUserName}}</td>
<td>{{ $vu->SystemUserDescription}}</td>
</tr>
#endforeach
Related
I have a regular Laravel view that renders a table. When I try to use Datatables on it, it does render the table but it seems to want to format it before the table is actually rendered. I'm confused because, by the time the view is rendered, the server-side work is already done. The only thing it's doing is to render the table with the object passed from the controller.
<table id="stockmovement" class="table table-hover" style="width:100%">
<tbody>
<thead>
<th>Material</th>
<th>Tipo</th>
<th>Quantidade</th>
<th>Valor total</th>
<th>Data</th>
<th>Ordem</th>
<th colspan="3"></th>
</thead>
#foreach($ordercontents as $ordercontent)
<tr>
<td>{{ $ordercontent->material_name }}</td>
<td>{{ $ordercontent->type }}</td>
<td>{{ $ordercontent->oc_weight }}</td>
<td>{{ number_format($ordercontent->oc_weight * $ordercontent->material_price, 2) }}</td>
<td>{{ $ordercontent->order_date }}</td>
<td>{{ $ordercontent->order_name }}</td>
</tr>
#endforeach
</tbody>
</table>
$(document).ready(function() {
$('#stockmovement').DataTable();
})
This is what I end up with:
I don't want to use AJAX to form my table. I've used plenty of vanilla PHP and DataTables instances before where it works just fine. I would appreciate any pointers on what I may be missing.
You have placed <tbody> in the wrong place. <tbody> should use under the </thead>.
Here is the code example:
<table id="stockmovement" class="table table-hover" style="width:100%">
<thead>
<th>Material</th>
<th>Tipo</th>
<th>Quantidade</th>
<th>Valor total</th>
<th>Data</th>
<th>Ordem</th>
</thead>
<tbody>
#foreach($ordercontents as $ordercontent)
<tr>
<td>{{ $ordercontent->material_name }}</td>
<td>{{ $ordercontent->type }}</td>
<td>{{ $ordercontent->oc_weight }}</td>
<td>{{ number_format($ordercontent->oc_weight * $ordercontent->material_price, 2) }}</td>
<td>{{ $ordercontent->order_date }}</td>
<td>{{ $ordercontent->order_name }}</td>
</tr>
#endforeach
</tbody>
</table>
Add tr tag inside the thead tag.
The foreach loop should be in the opening and closing tbody tag.
It should look like this:
<table id="stockmovement" class="table table-hover" style="width:100%">
<thead>
<tr>
<th>Material</th>
<th>Tipo</th>
<th>Quantidade</th>
<th>Valor total</th>
<th>Data</th>
<th>Ordem</th>
</tr>
</thead>
<tbody>
#foreach($ordercontents as $ordercontent)
<tr>
<td>{{ $ordercontent->material_name }}</td>
<td>{{ $ordercontent->type }}</td>
<td>{{ $ordercontent->oc_weight }}</td>
<td>{{ number_format($ordercontent->oc_weight * $ordercontent->material_price, 2) }}</td>
<td>{{ $ordercontent->order_date }}</td>
<td>{{ $ordercontent->order_name }}</td>
</tr>
#endforeach
</tbody>
</table>
I just trying to make a group of students who have the same group ID and calculate the CGPA of only those students who have belong to the same Group.
Refrence Example
Here's is the code for Controller
public function View_GroupStudent()
{
$allot_app = AllotmentApps::select(
"AllotmentApps.grpID",
"AllotmentApps.sname",
"AllotmentApps.cgpa"
)
->orderBy('grpID')
->get();
return view('deny', compact('allot_app'));
}
Views:
<table class="table table-bordered">
<tr>
<th>Group Id</th>
<th>Student Name</th>
<th>Individuals CGPA</th>
<th>Group CGPA</th>
</tr>
<tr>
#foreach ($allot_app as $allot_app)
<td>{{ $allot_app->grpID }}</td>
<td>{{ $allot_app->sname }}</td>
<td>{{ $allot_app->cgpa }}</td>
<td>{{ $allot_app->sum('cgpa') }}</td>
</tr>
#endforeach
</table>
Also help me in creating a proper view for that.
I was confused by your image because the red numbers weren't the averages at all. You should be able to achieve what you're trying to do with the following:
<table class="table table-bordered">
<tr>
<th>Group Id</th>
<th>Student Name</th>
<th>Individuals CGPA</th>
<th>Group CGPA</th>
</tr>
#foreach ($allot_app->groupBy('grpID') as $grouped)
#foreach ($grouped as $allot_app)
<tr>
<td>{{ $allot_app->grpID }}</td>
<td>{{ $allot_app->sname }}</td>
<td>{{ $allot_app->cgpa }}</td>
<td>{{ number_format($grouped->avg('cgpa'), 2) }}</td>
</tr>
#endforeach
#endforeach
</table>
I'm sorry, I have a problem with my laravel pagination Gives me one by one page for example, in my table 16 row I make paginate (10), the pagination gives me in the first page from 1 to 10 and in the second page from 1 to 6 I want the normal pagination from 1 to 10 and from 11 to 16 any help, please
public function allappointmnts(){
$allapo=DB::table('bookappoitments')->orderBy('times.id')
->join('users','bookappoitments.users_id','users.id')
->join('times','bookappoitments.times_id','times.id')
->join('dates','bookappoitments.Dates_id','dates.id')
->paginate(10);
return view('admin.Managers.allappoinments',compact('allapo'));
}
in the blade page:
<div class="text-center">
{!! $allapo->links(); !!}
</div>
The table :
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
#foreach($allapo as $Appointments)
<td>{{ $loop->index+1 }}</td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td>
<a class="btn btn-success btn-mini deleteRecord " href="{{url('showbymanagment',$Appointments->id)}}">Show</a>
</td>
</tr>
#endforeach
Your problem is that you're using the current index of each loop - which will always be within the range of 1-10 of each page (since you have 10 elements per page).
You need to get the current page you're on using
$allapo->currentPage()
Then get the number of elements per page you got, using
$allapo->perPage()
Multiply these two, and it will be the base number for your pagination, meaning that its this number you should increment from.
The indexed table should then be
{{ $allapo->currentPage() * $allapo->perPage() + $loop->index }}
instead of
{{ $loop->index+1 }}
Then, to fix the heading-numbers (10 and 6 at the top), get the total number of results instead of the count of the page using
$allapo->total()
See the Laravel documentation for more details.
Not entirely sure, but you will need to write some sort of function to fix this.
Essentially you need to do this:
Get the page number (ex: 1)
Multiply it by the rows per page (ex: 10)
Add the iteration number
Subtract the per page number
function correct_pagination_numbers($cp, $pp, $counter)
{
$c = (($pp * $cp) + $counter) - $pp;
return $c;
}
Then you can call the function in your view like so:
<td>{{ correct_pagination_numbers($allapo->currentPage(), $allapo->perPage(), $loop->index) }}</td>
It would probably be the best solution to do this in a helper file. If you don't know how to create a helper file and autoload it, you can look here.
Try this code:
<?php $i = $lists->perPage() * ($lists->currentPage() - 1); ?>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
#foreach($allapo as $Appointments)
<td><?php $i++; ?>{{ $i }} </td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td><a class="btn btn-success btn-mini deleteRecord " href="
{{url('showbymanagment',$Appointments->id)}}">Show</a></td>
</tr>
#endforeach
Try ths
#foreach($allapo as $key => $Appointments)
{{ $key + $allapo->firstItem() }}
#endforeach
to see the correct number change the line
<td>{{ $loop->index+1 }}</td>
to:
<td>{{ ($allapo->currentPage() - 1) * $allapo->perPage() + $loop->iteration }} <td>
I use Laravel to show data from Mysql to View by multi-queries.
Here is my Route:
Route::get('/procinstdetail','ProcDetailController#index');
And here is my controller:
use App\act_hi_taskinst;
use View;
class ProcDetailController extends Controller
{
private $act_hi_taskinst;
public function __construct(act_hi_taskinst $act_hi_taskinst) {
$this -> act_hi_taskinst = $act_hi_taskinst;
}
public function index(act_hi_taskinst $act_hi_taskinst, Request $request)
{
$procinstid = $request->get('id');
return View::make('datatrackingdetail')->with('data', $this->act_hi_taskinst->getData($procinstid));
}
}
And my model:
class act_hi_taskinst extends Model
{
public function getData($procinstid) {
$data = array();
$data['taskData'] = DB::select("SELECT NAME_, PRIORITY_, ASSIGNEE_, DUE_DATE_, START_TIME_, END_TIME_, PROC_DEF_ID_ FROM act_hi_taskinst WHERE PROC_INST_ID_ = $procinstid");
$data['varData'] = DB::select("SELECT NAME_, TEXT_ FROM act_hi_varinst WHERE PROC_INST_ID_ = $procinstid");
$data['subprocessData'] = DB::select("SELECT * FROM act_hi_procinst WHERE SUPER_PROCESS_INSTANCE_ID_ = $procinstid");
return $data;
}
}
Final is fetch data to view:
<body>
<h2>Task</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Priority</th>
<th>Assignee</th>
<th>Due Date</th>
<th>Created</th>
<th>Completed</th>
</tr>
#if(isset($data))
#foreach($data as $processTaskDataValue)
<tr>
<td>{{ $processTaskDataValue -> NAME_ }}</td>
<td>{{ $processTaskDataValue -> PRIORITY_ }}</td>
<td>{{ $processTaskDataValue -> ASSIGNEE_ }}</td>
<td>{{ $processTaskDataValue -> DUE_DATE_ }}</td>
<td>{{ $processTaskDataValue -> START_TIME_ }}</td>
<td>{{ $processTaskDataValue -> END_TIME_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Variable</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
#if(isset($data))
#foreach($data as $processVarDataValue)
<tr>
<td>{{ $processVarDataValue -> NAME_ }}</td>
<td>{{ $processVarDataValue -> TEXT_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Sub Process</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>ID_</th>
<th>PROC_INST_ID_</th>
<th>BUSINESS_KEY_</th>
<th>PROC_DEF_ID_</th>
<th>START_TIME_</th>
<th>END_TIME_</th>
<th>DURATION_</th>
<th>START_USER_ID_</th>
<th>START_ACT_ID_</th>
<th>END_ACT_ID_</th>
<th>SUPER_PROCESS_INSTANCE_ID_</th>
<th>DELETE_REASON_</th>
<th>TENANT_ID_</th>
<th>NAME_</th>
</tr>
#if(isset($data))
#foreach($data as $subprocessDataValue)
<tr>
<td> {{$subprocessDataValue -> ID_ }}</td>
<td>{{ $subprocessDataValue -> PROC_INST_ID_ }}</td>
<td>{{ $subprocessDataValue -> BUSINESS_KEY_ }}</td>
<td>{{ $subprocessDataValue -> PROC_DEF_ID_ }}</td>
<td>{{ $subprocessDataValue -> START_TIME_ }}</td>
<td>{{ $subprocessDataValue -> END_TIME_ }}</td>
<td>{{ $subprocessDataValue -> DURATION_ }}</td>
<td>{{ $subprocessDataValue -> START_USER_ID_ }}</td>
<td>{{ $subprocessDataValue -> START_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue -> END_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue -> SUPER_PROCESS_INSTANCE_ID_ }}</td>
<td>{{ $subprocessDataValue -> DELETE_REASON_ }}</td>
<td>{{ $subprocessDataValue -> TENANT_ID_ }}</td>
<td>{{ $subprocessDataValue -> NAME_ }}</td>
</tr>
#endforeach
#endif
</table>
</body>
But I receive error:
Trying to get property 'NAME_' of non-object.
What's wrong with my code?
I'm new with Laravel so I really don't know how to fix it.
In your Model you are creating array with key taskData, varData and subprocessData and you forgot to use this key to your $data array while getting data
<body>
<h2>Task</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Priority</th>
<th>Assignee</th>
<th>Due Date</th>
<th>Created</th>
<th>Completed</th>
</tr>
#if(isset($data))
#foreach($data['taskData'] as $processTaskDataValue)
<tr>
<td>{{ $processTaskDataValue->NAME_ }}</td>
<td>{{ $processTaskDataValue->PRIORITY_ }}</td>
<td>{{ $processTaskDataValue->ASSIGNEE_ }}</td>
<td>{{ $processTaskDataValue->DUE_DATE_ }}</td>
<td>{{ $processTaskDataValue->START_TIME_ }}</td>
<td>{{ $processTaskDataValue->END_TIME_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Variable</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>Name</th>
<th>Value</th>
</tr>
#if(isset($data))
#foreach($data['varData'] as $processVarDataValue)
<tr>
<td>{{ $processVarDataValue->NAME_ }}</td>
<td>{{ $processVarDataValue->TEXT_ }}</td>
</tr>
#endforeach
#endif
</table>
<h2>Sub Process</h2>
<table border="1" cellspacing = "0" cellpadding = "3">
<tr>
<th>ID_</th>
<th>PROC_INST_ID_</th>
<th>BUSINESS_KEY_</th>
<th>PROC_DEF_ID_</th>
<th>START_TIME_</th>
<th>END_TIME_</th>
<th>DURATION_</th>
<th>START_USER_ID_</th>
<th>START_ACT_ID_</th>
<th>END_ACT_ID_</th>
<th>SUPER_PROCESS_INSTANCE_ID_</th>
<th>DELETE_REASON_</th>
<th>TENANT_ID_</th>
<th>NAME_</th>
</tr>
#if(isset($data))
#foreach($data['subprocessData'] as $subprocessDataValue)
<tr>
<td><a href= "{{ url('/procinstdetail') }}?id={{
$subprocessDataValue -> ID_ }}&endtime={{ $subprocessDataValue ->
END_TIME_ }}"> {{$subprocessDataValue -> ID_ }}</a></td>
<td>{{ $subprocessDataValue->PROC_INST_ID_ }}</td>
<td>{{ $subprocessDataValue->BUSINESS_KEY_ }}</td>
<td>{{ $subprocessDataValue->PROC_DEF_ID_ }}</td>
<td>{{ $subprocessDataValue->START_TIME_ }}</td>
<td>{{ $subprocessDataValue->END_TIME_ }}</td>
<td>{{ $subprocessDataValue->DURATION_ }}</td>
<td>{{ $subprocessDataValue->START_USER_ID_ }}</td>
<td>{{ $subprocessDataValue->START_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue->END_ACT_ID_ }}</td>
<td>{{ $subprocessDataValue->SUPER_PROCESS_INSTANCE_ID_ }}</td>
<td>{{ $subprocessDataValue->DELETE_REASON_ }}</td>
<td>{{ $subprocessDataValue->TENANT_ID_ }}</td>
<td>{{ $subprocessDataValue->NAME_ }}</td>
</tr>
#endforeach
#endif
</table>
</body>
DB::select() will return an Array. So call it's property accordingly.
small POC
Update: Also as per other answer, you are not iterating over elements of $data, not actual data that you get from DB::select.
Okay so I've hit a wall for some reason and I can't figure this out. I wan't to check if there are any records in a query and then use an #if in my view to say either "yes, there are records" or "none". Nothing I've tried is working..
What I want:
<div class="col-md-12 col-style">
<h1 class="no-border">YOUR LATEST CONVERSIONS</h1>
#if(something here that lets me test if $transactions is empty)
<table class="table table-striped">
<tr>
<th>#</th>
<th>Type</th>
<th>User</th>
<th>Amount</th>
<th>Value</th>
<th>Result</th>
<th>Result Value</th>
<th>Date</th>
</tr>
#foreach($transactions as $transaction)
<tr>
<td>{{ $transaction->id }}</td>
<td>{{ $transaction->status }}</td>
<td>{{ $transaction->username }}</td>
<td>{{ $transaction->amount }}</td>
<td>{{ $transaction->value }}</td>
<td>{{ number_format($transaction->result, 2) }}</td>
<td>{{ $transaction->result_value }}</td>
<td>{{ $transaction->created_at }}</td>
</tr>
#endforeach
</table>
#else
yo no records
#endif
</div>
My controller:
public function index($username)
{
$user = User::where('username', $username)->firstOrFail();
$id = $user->id;
$transactions = Transactions::where('user_id', '=', $id)->take(5)->get();
return view('user.profile', compact('user', '=', 'userCurrency', 'transactions'));
So if you see in the top part there's a basic #if. Maybe I'm over thinking it, or am I passing in something that cant be checked the way I want it to?
Thanks!
#if (!$transactions->isEmpty())
...
#endif
this use laravel collection method do the trick.
it is as easy as:
#if(count($transactions) > 0)
#if($transactions) should do the trick.