I am trying to send an array per compact but when viewing it it throws an error.
SaleController.php
public function generarRecibo($id)
{
$sales = Sale::with('client', 'products')->where('id', '=', $id)->get();
$pdf = PDF::loadView('pdf.sales-recibo', compact(['sales']) );
return $pdf->stream('Recibo N° '.$id.'.pdf');
}
sales-recibo.blade.php
<table class="table">
<tbody>
#foreach ($sales->products as $product)
<tr>
<td style="border: 0px;" colspan="3">{{ $product->name }}</td>
</tr>
<tr>
<td style="border: 0px;">
<ul>
<li>{{ $product->quantity }} X ${{ number_format($product->price, 0,',','.') }}</li>
</ul>
</td>
<td style="border: 0px;" width="150px"></td>
<td style="border: 0px;" width="150px">${{ number_format($product->price, 0,',','.') }}</td>
</tr>
#endforeach
</tbody>
</table>
Instead of get() use find() method
$sales = Sale::with('client', 'products')->find($id);
and also you have issue with compact
$pdf = PDF::loadView('pdf.sales-recibo', compact('sales') );
Related
I am working on the below code, where the same question can have multiple images as an answer.
So, they are displaying properly but, with every image, the same question is repeating multiple times.
So, I want the question to display only once and below that the answers should be displayed. Below is the code. I have created a table and the images will be displayed after the question. Same has been highlighted below. I have done some POC, please have a look.
<!--Question and Answer Section Open-->
#if($submited_documents->count() !=0)
<table class="table table-bordered">
<tbody>
#if(count($submited_documents) > 0)
#foreach($submited_documents as $documents)
<tr>
<th style="width:50% !important; border:1px solid lightgray;"><strong>Question{{$documents->sequence}} : </strong></th>
<th style="border:1px solid lightgray; "><strong>Answer : </strong></th>
</tr>
<tr>
<td>{{ $documents->question }}</td>
<td>{{ $documents->comments }}</td>
</tr>
#endforeach
#endif
</tbody>
</table>
<table>
<tbody>
#foreach($submited_documents as $documents)
<tr>
<td style="border-radius: 2px;">
<strong>Question{{$documents->sequence}} : </strong>{{ $documents->question }}
</td>
</tr>
#if(count($documents->pictures) > 0 )
#foreach($documents->pictures as $document_picture)
<tr>
<td class="td_class">
#if($document_picture->filename != null)
<a style="" href="{{ URL::to('public/uploads/pickups/'.$document_picture->filename) }}" target="new">
<img src="{{ URL::to('public/uploads/pickups/'.$document_picture->filename) }}"
alt="{{ $document_picture->filename }}" title="{{ $document_picture->filename }}"
style="width: 50% !important;height: 50% !important;" ></a><br>
#endif
</td>
</tr>
#endforeach
#endif
#endforeach
</tbody>
</table>
#endif
<!--Question and Answer Section End-->
Any help is appreciated..
Hi Guy's Im always getting an error from laravel 5.4.
Im creating a list of members... but when i use #foreach it says
ErrorException in 6163a8b030c7474bc8eaad359ab99eb61ebdb127.php line 38:
Trying to get property of non-object (View: E:\wamp64\www\gplspring2017\resources\views\admin\memberlist.blade.php)
Here's my controller
public function listmember(Request $request, $idteam)
{
$teams = DB::table('gpl_team')->where('gpl_team_id', $idteam)->first();
$count = count($teams);
if (!$count) {
return redirect('404');
} else {
return view('/admin/memberlist', ['team' => $teams]);
}
}
and here's my view code:
<table class="table table-striped">
<tr>
<td style="width:15%;"></td>
<td style="width:25%;">Summoners Name</td>
<td style="width:25%;">Name</td>
<td style="width:25%;">Role</td>
<td style="width:10%;"></td>
</tr>
<?php
$qmember = DB::table('team_member')->where('gpl_team_id', $team->gpl_team_id)->first();
$counting = count($qmember);
?>
#if (! $counting)
<tr>
<td colspan="4"> No Recored! </td>
</tr>
#else
#foreach($qmember as $get_member)
<tr>
<td><img src="{{ $get_member->member_pic }}" /></td>
<td></td>
<td></td>
<td></td>
<td>
<div class="glyphicon glyphicon-pencil"></div> |
<div class="glyphicon glyphicon-trash"></div>
</td>
</tr>
#endforeach
#endif
</table>
When i remove the foreach the code is working.. but i try to add the #foreach($qmember as $get_member) it not working anymore...
Check this line:
$qmember = DB::table('team_member')->where('gpl_team_id', $team->gpl_team_id)->first();
when you are using first() then it does not return an Std Class object. If you want it so then use get()
Using first() method you are fetching only one record from DB that match with the ID (First one matched). You need to use get().
Controller:
public function listmember(Request $request, $idteam)
{
$teams = DB::table('gpl_team')->where('gpl_team_id', $idteam)->get(); //Use get() if you expect more than one result not first()
$count = count($teams);
if(! $count)
{
return redirect('404');
}
else
{
return view('/admin/memberlist', ['teams' => $teams]);// this team variable must be used in the blade
}
}
View:
<table class="table table-striped">
<tr>
<td style="width:15%;"></td>
<td style="width:25%;">Summoners Name</td>
<td style="width:25%;">Name</td>
<td style="width:25%;">Role</td>
<td style="width:10%;"></td>
</tr>
<?php
$qmember = DB::table('team_member')->where('gpl_team_id', $team->gpl_team_id)->first();
$counting = count($qmember);
?>
#if (! $counting)
<tr>
<td colspan="4"> No Recored! </td>
</tr>
#else
#foreach($teams as $team)
<tr>
<td><img src="{{ $team['member_pic'] }}" /></td>
<td></td>
<td></td>
<td></td>
<td>
<div class="glyphicon glyphicon-pencil"></div> |
<div class="glyphicon glyphicon-trash"></div>
</td>
</tr>
#endforeach
#endif
</table>
This is controller part
$users_list = User::where('id', '>', 4)
->where('status', 1)
->orderBy('id')
->get();
$companys = WorkFor::all();
$categories = TaskCetagorys::all();
//$report_table = array();
foreach($users_list as $user){
$report_table = array();
$user_tasks = Task::select('task_date',DB::raw('group_concat(tasks.workfor_name) as workfor_name'),'taskcategory_name',DB::raw('group_concat(tasks.description SEPARATOR ",,,") as description'))
->wherebetween('task_date', array("$start_task_date", "$end_task_date"))
->where('asign_id', '=', $user->id)
->where('status', 1)
->groupBy('workfor_id')
->orderBy('task_date')
->get();
}
This is my view part
<table id = "datatable" class="table table-striped table-bordered" style="font-size: 85%">
<thead>
<tr>
<th class="bg-primary col-sm-2" >
<font size="4">
Employee
</font>
</th>
{{--<th class="bg-danger">--}}
{{--<font size="4">--}}
{{--Company--}}
{{--</font>--}}
{{--</th>--}}
{{--<th class="bg-success">--}}
{{--<font size="4">--}}
{{--Category--}}
{{--</font>--}}
{{--</th>--}}
{{--<th class="bg-warning">--}}
{{--<font size="4">--}}
{{--Task--}}
{{--</font>--}}
{{--</th>--}}
</tr>
</thead>
<tbody>
#foreach ($report_table_all as $report)
<?php
$name = $report[0]['user_name'];
$user_designation = $report[0]['user_designation'];
?>
<tr>
<td>
{{--<font size="2">--}}
<strong>{{$name}}</strong></br>
{{--</font>--}}
<font size="1">
{{$user_designation}}
</font>
</td>
<td>
#foreach ( $report as $daily_report )
<table class="table table-striped table-bordered datatable" style="font-size: 85%">
<thead>
<tr class="primary" style="font-size: 15px;">
<th class="bg-info">Concern</th>
<th class="bg-warning">Category</th>
<th class="bg-success">Task</th>
<th class="bg-danger">Date</th>
</tr>
</thead>
<?php
$total = 0;
$sn = 1;
$sn_total = '*';
?>
#foreach($daily_report['user_task_lists'] as $user_task)
<tr>
<td style="background-color: rgba(227, 255, 140, 0.98); ">
<center>{{$user_task->workfor_name}}</center>
</td>
<td>
<table class="table table-striped table-bordered datatable" style="font-size: 85%">
<tr>
<td style="font-size: 13px;background-color: rgba(19, 214, 255, 0.98)">
{{$sn}}.{{ $user_task->taskcategory_name }}
<?php $sn += floatval(1) ?>
</td>
</tr>
</table>
</td>
<td style="font-size: 12px;">
{{ $user_task->description}}
</td>
<td>
{{date('d-M-Y',strtotime($user_task->task_date))}}
</td>
</tr>
#endforeach
</table>
</td>
#endforeach
</tr>
#endforeach
</tbody>
</table>
I am using laravel 5.2 version.in my controller i fetch one column data using group_concat function.When i showing these data using view,the same name repeats many times in a row.but i want to show these repeated data only one time.for example,i fetched my workfor_name from database using group_concat.then when i showimg them the workfor_name repeats many times as PALO,PALO,PALO,PALO,PALO,PALO,PALO,PALO,PALO in a row.i want only one PALO in my row.need help.!!!
this is my view page
Add the keyword DISTINCT to your GROUP_CONCAT call.
$user_tasks = Task::select('task_date',DB::raw('group_concat(DISTINCT tasks.workfor_name) as workfor_name'),'taskcategory_name',DB::raw('group_concat(DISTINCT tasks.description SEPARATOR ",,,") as description'))
->wherebetween('task_date', array("$start_task_date", "$end_task_date"))
->where('asign_id', '=', $user->id)
->where('status', 1)
->groupBy('workfor_id')
->orderBy('task_date')
->get();
Trying to create a PDF invoice using barryvdh's laravel dompdf wrapper. I want the invoice to begin on a new page when a certain number of rows is reached. However I'm unsure on how to do it since I don't get the expected results. Here is my controller:
function invoice() {
$resellerId = Input::get('resellerId');
$startdate = Input::get('invoiceStartDate');
$enddate = Input::get('invoiceEndDate');
$orders = \App\order::where('reseller',1)->orderBy('date', 'desc')->where('customer_id' , $resellerId )->where('date', '>=',$startdate)->where('date', '<=',$enddate)->get();
$pdf = PDF::loadView('pdf.invoicePrint',['orders' => $orders]);
// $PDFOutput = $pdf->output();
return $pdf->stream("trestaki.pdf");
}
And here is the relevant portion of the blade:
<table style="border:1px solid #000;width: 100%;">
<tr>
<td>
<span style="font-size: 14px;font-weight: 900;">Art. Nr.</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Benämning</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Antal</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Pris</span>
</td><td>
<span style="font-size: 14px;font-weight: 900;">Summa</span>
</td></tr>
<?php $i=0; ?>
#foreach($orders as $order)
<tr>
<td>{{ $order->order_id }}</td>
<td>{{ $order->getProduct->mobile }} {{ $order->getProduct->model }}</td>
<td>1</td>
<td>{{ $order->price }}</td>
<td>{{ $order->price }}</td>
</tr>
<?php
$i++;
if($i % 25 == 0)
echo "<div style='page-break-after: always;'></div>";
?>
#endforeach
<tr>
<td colspan=5 style="padding-top: 20px;">
<table style="width: 45%;">
<tr>
<td>
<span style="font-size: 14px;font-weight: 900;">Moms %</span>
</td>
<td>
<span style="font-size: 14px;font-weight: 900;">Netto</span>
</td>
<td>
<span style="font-size: 14px;font-weight: 900;">Moms</span>
</td>
<td>
<span style="font-size: 14px;font-weight: 900;">Summa</span>
</td>
</tr>
<tr>
<td>25%</td>
<td>639,20</td>
<td>159,80</td>
<td>799,00</td>
</tr>
</table>
</td>
</tr>
</table>
The thing is that if I remove all the closing tags from the echo, the webpage times out.
The problem was the fixed position of the main div. After removing it the page did break correctly.
i have some coding, i wanna to update multiple data from select option value in database using laravel 5.1. i'm using ajax onchange="form.submit()", so i can update data without submit.
this is my view
{!! Form::model($UserAccess,['method' => 'POST','url'=>['setting/updaterole']]) !!}
<table class="dataTable" id="table-user">
<thead class="grey lighten-3">
<tr>
<td class="center-align no-sort">Photo</td>
<td class="center-align">Fullname</td>
<td class="center-align">Rule</td>
<td class="center-align">Action</td>
</tr>
</thead>
<tbody>
<?php $hitung = $UserAccess->count(); ?>
#foreach($UserAccess as $list)
<tr>
<td class="center-align" width="50">
#if($list->avatar == NULL)
<img class="circle responsive-img" width="50" src="{{asset(config('param.url_uploads').'blank.jpg')}}"/>
#else
<img class="circle responsive-img" width="50" src="{{$list->avatar}}"/>
#endif
</td>
<td class="red1-text lato-bold center-align">{{$list->name}}</td>
<td class="center-align" width="150">
<select id="selectrole" name="selectrole" onchange="form.submit()">
#foreach($UserAccessRole as $listRole)
<option value="{{$listRole->id}}" #if($list->user_access_role_id_fk == $listRole->id) selected="selected"#endif>{{$listRole->name}}</option>
#endforeach
</select>
</td>
<input type = "hidden" value = "{{$list->id}}" name = "idmain">
#if($hitung > 2)
<td class="center-align">
<a href = "remove_access/{{$list->id}}/delete" >Remove Access<a/>
</td>
#else
<td class="center-align">Remove Access</td>
#endif
</tr>
#endforeach
</tbody>
</table>
{!! Form::close() !!}
this is my controller
public function doUpdateAccessRole(Request $request)
{
$UserAccess = UserAccess::orderBy('name', 'asc')->get();
$id_main = $request->input('idmain');
$id_role = $request->input('selectrole');
$Role = UserAccess::findOrFail($id_main);
$Role->user_access_role_id_fk = $id_role;
$Role->update($request->all());
return redirect('setting/useraccess');
}
this is my route
Route::post('setting/updaterole',['uses'=>'SettingController#doUpdateAccessRole','as'=>'updateaccessrole']);
using my coding update function already work, but just last id has been update. please help me, thank you
my code already work. just add foreach in my controller. like this, my controller :
public function doUpdateAccessRole(Request $request)
{
$UserAccess = UserAccess::all();
foreach($UserAccess as $list)
{
$id_main = $request->input('idmain'.$list->id);
$id_role = $request->input('selectrole'.$list->id);
$Role = UserAccess::find($id_main);
$Role->user_access_role_id_fk = $id_role;
$Role->update($request->all());
}
return redirect('setting/useraccess');
}
and this my view :
{!! Form::model($UserAccess,['method' => 'POST','url'=>['setting/updaterole']]) !!}
<table class="dataTable" id="table-user">
<thead class="grey lighten-3">
<tr>
<td class="center-align no-sort">Photo</td>
<td class="center-align">Fullname</td>
<td class="center-align">Rule</td>
<td class="center-align">Action</td>
</tr>
</thead>
<tbody>
<?php $hitung = $UserAccess->count(); ?>
#foreach($UserAccess as $list)
<tr>
<td class="center-align" width="50">
#if($list->avatar == NULL)
<img class="circle responsive-img" width="50" src="{{asset(config('param.url_uploads').'blank.jpg')}}"/>
#else
<img class="circle responsive-img" width="50" src="{{$list->avatar}}"/>
#endif
</td>
<td class="red1-text lato-bold center-align">{{$list->name}}</td>
<td class="center-align" width="150">
<select id="selectrole" name="selectrole{{$list->id}}" onchange="form.submit()">
#foreach($UserAccessRole as $listRole)
<option value="{{$listRole->id}}" #if($list->user_access_role_id_fk == $listRole->id) selected="selected"#endif>{{$listRole->name}}</option>
#endforeach
</select>
</td>
<input type = "hidden" value = "{{$list->id}}" name = "idmain{{$list->id}}">
#if($hitung > 2)
<td class="center-align">
<a href = "remove_access/{{$list->id}}/delete" >Remove Access<a/>
</td>
#else
<td class="center-align">Remove Access</td>
#endif
</tr>
#endforeach
</tbody>
</table>
{!! Form::close() !!}
and now my coding already work.