I'm developing an aplication to manage multiples branches for a fast food locale, it's up in a shared hosting, and trying to use barryvdh/laravel-dompdf library to print in a thermal printer (client side) two tickets (one for invoice and other for order). The idea is when the invoice is registered, then show the options to print the two tickets. But right now the web print preview doesn't show, only register the invoice and log show this error 'PrinterController::pdf Invalid characters passed for attempted conversion, these have been ignored'. The aplication uses Laravel 5.8, php 7.3 and laravel-dompdf 0.8.5.
I would appreciate any help, I've been stuck for several days with this...
SalesController:
public function store(Request $request){
try{
$data = $request->all();
$client = json_decode($data['client']);
$till = Till::where('id', session('till'))->first();
DB::beginTransaction();
// ============================= INVOICE CREATION ==================================
$branch_id = Branch::where('id', auth()->user()->branch_id)->pluck('code')->first();
$user_code = (integer) substr((string) auth()->user()->ci, -3);
$previous_id = Invoice::whereRaw("id = (select max(id) from invoices where id like '" . $branch_id . $user_code . "%')")->pluck('id')->first();
if ($previous_id == null) {
$pre_id = $branch_id . $user_code;
$id = str_pad($pre_id, 10, "0", STR_PAD_RIGHT);
}
if ($previous_id != null)
$id = $previous_id + 1;
$invoice = new Invoice();
$invoice->id = $id;
$invoice->payment_id = 1;
$invoice->client_id = $client->id;
$invoice->received = $data['total_received'];
$invoice->total = 0;
$invoice->save();
// ============================= INVOICE DETAIL ====================================
$product_detail = $request->session('products')->all();
$sum = 0;
foreach ($product_detail['products'] as $item) {
$detail = new InvoiceDetail();
$detail->invoice_id = $invoice->id;
$detail->product_id = $item->id;
$detail->quantity = $item->quantity;
$detail->sub_total = (integer) $item->quantity*(integer) $item->price;// modificar a sub total
$detail->save();
$sum += $detail->sub_total;
$actual_stock = Stock::where('product_id', $item->id)->where('branch_id', auth()->user()->branch_id)->first();
$new_stock = (integer) $actual_stock->quantity - (integer) $item->quantity;
if ($item->quantity > $actual_stock->quantity)
return redirect()->back()->with('error', 'La cantidad solicitada supera el stock disponible');
$stock = Stock::find($actual_stock->id);
$stock->quantity = $new_stock;
$stock->save();
$stock_history = new StockHistory();
$stock_history->stock_id = $stock->id;
$stock_history->product_id = $item->id;
$stock_history->type = 'sales';
$stock_history->old_quantity = $actual_stock->quantity;
$stock_history->new_quantity = $new_stock;
$stock_history->ext_trans = $invoice->id;
$stock_history->user_id = auth()->user()->id;
$stock_history->save();
}
// ================================= ORDER =========================================
$order = new Order();
$order->invoice_id = $invoice->id;
$order->status = 0;
$order->save();
// ================================= SALES =========================================
$sales = new Sales();
$sales->invoice_id = $invoice->id;
$sales->client_id = auth()->user()->id;
$sales->till_id = session('till');
$sales->save();
// ============================= TILL_TRANSACTION ==================================
$invoice = Invoice::find($invoice->id);
$invoice->total = $sum;
$invoice->save();
foreach (session('products') as $item) {
$old_quantity = Stock::where('product_id', $item->id)->where('branch_id', auth()->user()->branch_id)->first();
$update = Stock::find($old_quantity->id);
$update->quantity = $old_quantity->quantity - $item->quantity;
$update->save();
}
$till_transaction = new TillTransaction();
$till_transaction->till_id = session('till');
$till_transaction->type_id= 3;
$till_transaction->detail_id = $sales->id;
$till_transaction->cash_before_op = $till->actual_cash;
$till_transaction->cash_after_op = $till->actual_cash + $invoice->total;
$till_transaction->user_id = auth()->user()->id;
$till_transaction->save();
DB::commit();
$branch = Branch::where('id', auth()->user()->branch_id)->pluck('name')->first();
$change = $invoice->received - $invoice->total;
$printer = new PrinterController();
$printer->printPDF($invoice, $product_detail['products'], $branch, $change, $order);
session(["products"=>[]]);
return redirect()->back()->with('success', 'Se ha registrado la venta');
} catch (\Exception $e){
DB::rollBack();
Log::error('SalesController::store ' . $e->getMessage(), ['error_line' => $e->getLine()]);
return redirect()->back()->with('error', 'Oops parece que ocurrio un error, por favor intente nuevamente.');
}
}
PrinterController:
namespace App\Http\Controllers;
use Barryvdh\DomPDF\Facade as PDF;
use Illuminate\Support\Facades\Log;
class PrinterController extends Controller
{
public function printPDF($invoice, $products, $branch, $change, $order){
try{
$data = [
'invoice' => $invoice,
'product_detail' => $products,
'branch' => $branch,
'change' => $change,
'order' => $order
];
$invoice = PDF::loadView('ticket.invoice', $data);
return $invoice->stream('test.pdf');
} catch (\Exception $e){
Log::error('PrinterController::pdf ' . $e->getMessage(), ['error_line' => $e->getLine()]);
return redirect()->back()->with('error', 'Oops parece que ocurrio un error al imprimir el ticket.');
} catch (\Throwable $e) {
Log::error('PrinterController::pdf ' . $e->getMessage(), ['error_line' => $e->getLine()]);
return redirect()->back()->with('error', 'Oops parece que ocurrio un error al imprimir el ticket.');
}
}
}
Invoice view:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<style>
body {
font-family: Nunito }
.detail{
text-align: end !important;
}
</style>
</head>
<body>
<div class="ticket">
<div>
<img src="../images/logo.png" style="width: 130px; margin-left: 60px;">
<h4><strong>Nro de Orden: {{ $order->id }}</strong></h4>
<br>
<h5 style="margin-top: -15px"><strong>Nro Factura: {{ $invoice->id }}</strong></h5>
<h5 style="margin-top: -10px"><strong>Fecha: {{ date( "d/m/Y", strtotime($invoice->created_at)) }} </strong> <strong>Hora: {{ date( "H:i:s", strtotime($invoice->created_at)) }}</strong></h5>
</div>
<table>
<hr>
<thead>
<tr style="font-size: 17px">
<td><strong>Articulo</strong></td>
<td><strong>Cant.</strong></td>
<td style="padding-left: 10px"><strong>Precio</strong></td>
<td style="padding-left: 20px; text-align: right"><strong>Sub Total</strong></td>
</tr>
</thead>
<tbody>
#foreach($product_detail as $product)
<tr>
<td>{{ $product->name }}</td>
<td>{{ $product->quantity }}</td>
<td style="padding-left: 10px">{{ $product->price }}</td>
<td style="padding-left: 30px">{{ (integer) $product->quantity * (integer) $product->price }}</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr class="detail">
<td colspan="3" style="padding-top: 20px"><strong>Total: </strong></td>
<td style="padding-top: 20px">{{ $invoice->total }}</td>
</tr>
<tr class="detail">
<td colspan="3"><strong>Recibido: </strong></td>
<td>{{ $invoice->received }}</td>
</tr>
<tr class="detail">
<td colspan="3"><strong>Su Vuelto: </strong></td>
<td>{{ $change }}</td>
</tr>
</tfoot>
</table>
<hr>
<div style="margin-top: 9px; margin-bottom: -15px">
<h5 style="margin-bottom: -10px"><strong>Local: {{ $branch }}</strong></h5>
<h5><strong>Cajero: {{ auth()->user()->name }}</strong></h5>
<h4>Gracias por su compra!</h4>
</div>
<p>--------------------------------------------</p>
<p style="font-size: 13px; text-align: center">DOCUMENTO NO VALIDO COMO FACTURA</p>
</div>
</body>
</html>
Order View:
<html>
<head>
<!-- Styles -->
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
<link href="{{ asset('fontawesome/css/all.css') }}" rel="stylesheet">
<style>
.ticket {
width: 283px;
max-width: 280px;
}
</style>
</head>
<body>
<div class="ticket" >
<table class="table" style="border-top: hidden">
<caption style="caption-side: top; text-align: center">ORDEN N° 002517</caption>
<caption style="caption-side: top; margin-top: -20px; margin-bottom: -15px">=============================</caption>
<caption style="caption-side: bottom; margin-top: -20px; margin-bottom: -15px">=============================</caption>
<caption style="caption-side: bottom; margin-bottom: -15px">Solicitado: 2019/12/30 -- 22:51:33</caption>
<thead>
<tr>
<th>Art.</th>
<th>Cant.</th>
</tr>
</thead>
<tbody>
<tr>
<td>Producto de prueba</td>
<td>10</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>
The error you're seeing
Invalid characters passed for attempted conversion, these have been ignored
is a PHP error related to parsing content from the font metrics. This issue (ref #2003) should be addressed in the recently-released 0.8.4 version of Dompdf.
Since laravel-dompdf required Dompdf 0.8 you should be able to composer update your install and hopefully see a the issue go away.
Related
I am trying to export to excel using PHP 7, Laravel 5.8, Maatwebsite Excel 3.1. I successfully display on the view blade and also perform the filter.
Model:
use App\UserResponse;
Controller
public function userresponseReport(Request $request,$export=false)
{
$data['title'] = 'User Response';
$userresponses = DB::table('user_response as g')
->select(
//DB::raw('DATE(g.created_at) as created_date'),
DB::raw('g.created_at as created_date'),
'g.msisdn',
'g.game_code',
'g.answer',
'g.answer_code',
'g.Amount_charged',
'g.payment_ref',
'g.status',
'g.user_channel'
)
->orderByRaw('g.created_at DESC');
$start_date = $request->start_date;
$end_date = $request->end_date;
$render=[];
if(isset($request->start_date) && isset($request->end_date))
{
$userresponses=$userresponses->whereBetween('created_at',[$start_date.' 00:00:00',$end_date.' 23:59:59']);
$render['start_date']=$request->start_date;
$render['end_date']=$request->end_date;
}elseif(isset($request->start_date))
{
$userresponses=$userresponses->where('created_at',$request->start_date);
$render['start_date']=$request->start_date;
}
if(isset($request->msisdn))
{
$userresponses=$userresponses->where('msisdn','like','%'.$request->msisdn.'%');
$render['msisdn']=$request->msisdn;
}
if(isset($request->game_code))
{
$userresponses=$userresponses->where('game_code','like','%'.$request->game_code.'%');
$render['game_code']=$request->game_code;
}
if(isset($request->user_channel))
{
$userresponses=$userresponses->where('user_channel','like','%'.$request->user_channel.'%');
$render['user_channel']=$request->user_channel;
}
if(!empty($export))
{
return Excel::download(new UserresponseExport($userresponses->get()), 'userresponse.xlsx');
}
$userresponses= $userresponses->orderBy('created_at','DESC');
$userresponses= $userresponses->paginate(15);
$userresponses= $userresponses->appends($render);
$data['userresponses'] = $userresponses;
return view('report.userresponseReport',$data);
}
Then after that, the view blade:
userresponseReport.blade.php
<div class="row" style="margin-bottom: 10px">
{{ Form::model(request(),['method'=>'get']) }}
<div class="col-sm-2">
{{ Form::text('msisdn',null,['class'=>'form-control','placeholder'=>'MSISDN']) }}
</div>
<div class="col-sm-2">
{{ Form::text('game_code',null,['class'=>'form-control','placeholder'=>'Game Code']) }}
</div>
<div class="col-sm-2">
{{ Form::text('user_channel',null,['class'=>'form-control','placeholder'=>'Channel']) }}
</div>
<div class="col-sm-2">
{{ Form::date('start_date',null,['class'=>'form-control','placeholder'=>'Date']) }}
</div>
<div class="col-sm-2">
{{ Form::date('end_date',null,['class'=>'form-control','placeholder'=>'Date']) }}
</div>
<div class="col-xs-2">
{{ Form::submit('Search',['class'=>'btn btn-warning']) }}
<i class="fa fa-file-excel-o"></i> Excel
</div>
{{ Form::close() }}
</div>
<div class="box box-primary">
<div class="box-header with-border">
<table class="table table-bordered table-hover table-striped table-condesed" id="commenter_info_table">
<caption></caption>
<thead>
<tr>
<td>#</td>
<td>Date</td>
<td>MSISDN</td>
<td>Game Code</td>
<td>Game Name</td>
<td>Answer</td>
<td>Channel</td>
</tr>
</thead>
<tbody>
#foreach($userresponses as $key => $userresponse)
<tr>
<td>{{ ++$key }}</td>
<!-- <td>{{ $userresponse->created_date }}</td>-->
<td>{{ date('Y-m-d h:i:s A', strtotime($userresponse->created_date)) }}</td>
<td>{{ $userresponse->msisdn }}</td>
<td>{{ $userresponse->game_code }}</td>
<td>
#if($userresponse->game_code=='101')
Trivia
#elseif($userresponse->game_code=='102')
Predict and Win
#elseif($userresponse->game_code=='103')
Party With the BBN
#elseif($userresponse->game_code=='104')
Grand Prize
#elseif($userresponse->game_code=='105')
Happy Hour
#elseif($userresponse->game_code=='106')
Power Boost
#endif
</td>
<td>{{ $userresponse->answer }}</td>
<td>{{ $userresponse->user_channel }}</td>
</tr>
#endforeach
<tr>
<td colspan="14">
{{ $userresponses->links() }}
</td>
</tr>
</tbody>
</table>
Then the Export
UserresponseExport
class UserresponseExport implements FromView, WithHeadings, ShouldAutoSize, WithEvents, WithMapping
{
protected $userresponses;
public function __construct($userresponses = null)
{
$this->userresponses = $userresponses;
}
public function view(): View
{
return view('report.userresponseReport', [
'userresponses' => $this->userresponses ?: DB::table('user_response as g')
->select(
DB::raw('g.created_at as created_date'),
'g.msisdn',
'g.game_code',
'g.answer',
'g.answer_code',
'g.Amount_charged',
'g.payment_ref',
'g.status',
'g.user_channel'
)
->orderByRaw('g.created_at DESC')
]);
}
private $headings = [
'Date Created',
'MSISDN',
'game_code',
'Answer',
'Channel'
];
public function headings(): array
{
return $this->headings;
}
public function registerEvents(): array
{
return [
AfterSheet::class => function(AfterSheet $event) {
$cellRange = 'A1:E1'; // All headers
$event->sheet->getDelegate()->getStyle($cellRange)->getFont()->setSize(14);
},
];
}
}
Route
Route::get('/report/userresponse-report/{export?}', ['as' => 'userresponseReport', 'uses' => 'ReportController#userresponseReport']);
On the view blade, when I clicked on search everything was okay. But when I click on export, I got this error:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Declaration of App\Exports\UserresponseExport::view(): App\Exports\View must be compatible with Maatwebsite\Excel\Concerns\FromView::view(): Illuminate\Contracts\View\View
What could have caused this error?
How do I resolve it?
This error indicates that your class App\Exports\UserresponseExport is not following the interface correctly.
By the error we can see that you need to have a method named view which you have, but your method have typehinted App\Exports\View as the return type instead of Illuminate\Contracts\View\View.
To fix this simply change your view method return type to Illuminate\Contracts\View\View.
Your code right now most likely says
public function view(): View
{
...
}
But as you are missing use Illuminate\Contracts\View\View; in your import statements, View is getting resolved to the current namespace of your class + the class you are trying to typehint, which results in App\Exports\View.
So another solution to this instead of typehinting the full namespace is to import Illuminate\Contracts\View\View, in your class by adding use Illuminate\Contracts\View\View; at the top of your file.
Help please ,I recover my data in frontend use jquery and I can display in console, now I want to insert these data in the database we are using ajax and laravel, here is my table.
Hi,help please ,I recover my data in frontend use jquery :
<table class="table table-bordered" id="mytable">
<tr>
<th>Archive</th>
<th><input type="checkbox" id="check_all"></th>
<th>S.No.</th>
<th>matricule</th>
<th>nom & prenom</th>
<th>salaire net</th>
<th>nbre de jour </th>
<th>prime</th>
</tr>
#if($salaries->count())
#foreach($salaries as $key => $salarie)
<tr id="tr_{{$salarie->id}}">
<td>archive</td>
<td><input type="checkbox" class="checkbox" data-id="{{$salarie->id}}"></td>
<td>{{ ++$key }}</td>
<td class="mat">{{ $salarie->matricule }}</td>
<td class="name">{{ $salarie->nom }} {{ $salarie->prenom }}</td>
<td class="salaireValue">{{ $salarie->salairenet }}</td>
<td ><input type="text" name="nbreJ" class="form-control" value="{{$data['nbr']}}"></td>
<td><input type="text" name="prime" class="form-control" value="0"></td>
</tr>
#endforeach
#endif
</table>
This is my code jquery which allows to recover my data
<script type="text/javascript">
$(document).ready(function () {
$('#check_all').on('click', function(e) {
if($(this).is(':checked',true))
{
$(".checkbox").prop('checked', true);
} else {
$(".checkbox").prop('checked',false);
}
});
$('.checkbox').on('click',function(){
if($('.checkbox:checked').length == $('.checkbox').length){
$('#check_all').prop('checked',true);
}else{
$('#check_all').prop('checked',false);
}
});
//get value
$('.add-all').on('click', function() {
var allChecked = $('.checkbox:checked');
for (var i = 0; i < allChecked.length; i++) {
var currentHtml = $(allChecked[i]).parent().siblings('.salaireValue')[0];
var currentHtml1 = $(allChecked[i]).parent().siblings('.name')[0];
var currentHtml2 = $(allChecked[i]).parent().siblings('.mat')[0];
var currentHtml3 = $(allChecked[i]).parent().siblings('.datea')[0];
var result = parseInt($(currentHtml)[0].innerText);
var result1 = $(currentHtml1)[0].innerText;
var result2 = parseInt($(currentHtml2)[0].innerText);
console.log(result);
console.log(result1);
console.log(result2);
}
});
});
</script>
This my controller I do not know how to write the function.
public function addMultiple(Request $request){
dd(request());
}
route
Route::post('mensuel', ['as'=>'salarie.multiple-add','uses'=>'SalarieController#addMultiple']);
When I generate a PDF, the text is working but the image is not showing an image. How can I solve this? How can I use an image in my PDF? In the below I have given some code of my problem.
This is the view code: all of the code is included in one field in the database.
view code :
<div class="tab-pane" id="sixweekletterwithauto" role="tabpanel" aria-labelledby="sixweekletterwithauto-tab">
<form action="patient/addcaseHistory" method="post" enctype="multipart/form-data">
<center>
<h2 style="margin-top: 0;color:#55518a">Case Notes</h2>
<textarea name="editor1" class="ckeditor">
<img src="../uploads/pic.jpg" width="1000px" height="200px">
<p> </p>
<table align="right" style="width:200px">
<tbody>
<tr>
<td> Dr M Takla</td>
</tr>
<tr>
<td> 621 Boronia Rd Wantirna South</td>
</tr>
<tr>
<td> VIC 3152</td>
</tr>
<tr>
<td> Ph 97380009 Fax</td>
</tr>
</tbody>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p>Dear Dr M Takla,,</p>
<p><strong>Re: Aryan Karat (DOB : 9/12/2008)</strong></p>
<p>Thank you for referring Aryan Karat, for assistance with “behaviour problems, hyperactivity and phobias”.</p>
<p>The therapeutic process with Aryan has focussed on reducing anxiety and improving self confidence and self esteem. I have worked on a number of cognitive and behavioural strategies to assist Aryan in managing his worry. His teacher and parents have reported some positive changes, however they continue to be concerned about his constant need for reassurance by adults and anxiety in some situations.</p>
<p>Further sessions with Aryan are recommended in order to ensure that the skills and strategies imparted can be reinforced and fully assimilated.</p>
<p>If you wish to discuss this matter further, I may be contacted at 0419 489 333.</p>
<p>Thank you again for your referral, and I look forward to your reply.</p>
<p>Yours Sincerely</p>
<p> </p>
<p>Ms Angela Delle-Vergini,<br />
Psychologist<br />
M.A.P.S (B.A, Grad Dip Psych, M.Psych (Counselling).</p>
<p> </p>
</textarea>
<script>
CKEDITOR.replace( 'editor2' );
CKEDITOR.add
</script>
</center>
<input type="hidden" name="patient_id" value='<?php echo $patient->id; ?>'>
<input type="hidden" name="date" value='<?php echo date('m-d-Y') ?>'>
<div style="margin-bottom: 30px;">
<button class="btn btn-blue">Save & Finalise</button>
</div>
</form>
</div>
controller code :
function addcaseHistory() {
$id = $this->input->post('id');
$patient_id = $this->input->post('patient_id');
$date = $this->input->post('date');
$description = $this->input->post('editor1');
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<div class="error">', '</div>');
$redirect = $this->input->post('redirect');
if (empty($redirect)) {
$redirect = 'patient/medicalHistory?id=' . $patient_id;
}
// Validating Name Field
$this->form_validation->set_rules('date', 'Date', 'trim|required|min_length[5]|max_length[100]|xss_clean');
// Validating Password Field
$this->form_validation->set_rules('editor1', 'Description', 'trim|required|min_length[5]|max_length[10000]|xss_clean');
if ($this->form_validation->run() == FALSE) {
if (!empty($id)) {
redirect("patient/editMedicalHistory?id=$id");
} else {
$this->load->view('home/dashboard'); // just the header file
$this->load->view('add_new');
$this->load->view('home/footer'); // just the header file
}
} else {
if (!empty($patient_id)) {
$patient_details = $this->patient_model->getPatientById($patient_id);
$patient_name = $patient_details->name;
$patient_phone = $patient_details->phone;
$patient_address = $patient_details->address;
} else {
$patient_name = 0;
$patient_phone = 0;
$patient_address = 0;
}
//$error = array('error' => $this->upload->display_errors());
$data = array();
$data = array(
'patient_id' => $patient_id,
'date' => $date,
'description' => $description,
'patient_name' => $patient_name,
'patient_phone' => $patient_phone,
'patient_address' => $patient_address,
);
if (empty($id)) { // Adding New department
$this->patient_model->insertMedicalHistory($data);
$this->session->set_flashdata('feedback', 'Added');
} else { // Updating department
$this->patient_model->updateMedicalHistory($id, $data);
$this->session->set_flashdata('feedback', 'Updated');
}
// Loading View
$data['settings'] = $this->settings_model->getSettings();
$this->load->view('home/dashboard2',$data); // just the header file
$this->load->view('medical_history', $data);
$this->load->view('home/footer'); // just the footer file
}
}
public function pdfdetails()
{
$id = $this->input->get('id');
$html_content .= $this->patient_model->getMedicalHistoryByPatientId2($id);
$this->pdf->loadHtml($html_content);
$this->pdf->render();
$this->pdf->stream("".$id.".pdf", array("Attachment"=>0));
}
Model code:
function getMedicalHistoryByPatientId2($id)
{
$this->db->where('id', $id);
$data = $this->db->get('medical_history');
foreach($data->result() as $row)
{
$output .= '<p>'."<img src='../uploads/'".$row->img_url."/>".$row->description.'</p>';
}
return $output;
}
I'm new on Laravel and try to implement real live search and filter on my project, but it doesn't work at all. I dont understand ajax ver much and just copy paste the code from other website. I tried to understand the code and I think its correct but it doesn't work, so please help. Thanks
Here is my controller
public function search(Request $request)
{
if($request->ajax())
{
$output = '';
$query = $request->get('query');
if($query != '')
{
$data = Service::table('service')
->where('keterangan', 'like', '%'.$query.'%')
->orWhere('biaya', 'like', '%'.$query.'%')
->get();
}
else
{
$data = Service::table('service')
->orderBy('kodeService', 'asc')
->get();
}
$total_row = $data->count();
if($total_row > 0)
{
foreach($data as $row)
{
$output .= '
<tr>
<td>'.$row->kodeService.'</td>
<td>'.$row->keterangan.'</td>
<td>'.$row->biayaService.'</td>
</tr>
';
}
}
else
{
$output = '
<tr>
<td align="center" colspan="5">No Data Found</td>
</tr>
';
}
$data = array(
'table_data' => $output
);
echo json_encode($data);
}
}
This is the script
$(document).ready(function(){
fetch_customer_data();
function fetch_customer_data(query = '')
{
$.ajax({
url:"{{ route('live_search.action') }}",
method:'GET',
data:{query:query},
dataType:'json',
success:function(data)
{
$('#table tbody').html(data.table_data);
}
});
}
$(document).on('keyup', '#search', function(){
var query = $(this).val();
fetch_customer_data(query)
});
});
Route :
Route::resource('service', 'ServiceController');
Route::get('service/search', 'Service#search')->name('live_search.action');
And index.blade
<table class="table table-striped table-hover table-bordered" id="table">
<thead>
<tr>
<th>Kode Service</th>
<th>Keterangan</th>
<th>Biaya</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
#foreach($service as $data)
<tr>
<td><?= $data->kodeService?></td>
<td><?= $data->keterangan ?></td>
<td><?= $data->biayaService?></td>
<td>
<a class="btn btn-sm btn-info" href="{{ route('service.edit', $data['kodeService']) }}"> <i class="oi oi-pencil"></i> Edit</a>
<button type="button" class="btn btn-sm btn-danger" data-toggle="modal" data-target="#myModal"><span class="oi oi-trash"></span> Hapus</button>
</td>
</tr>
#endforeach
</tbody>
</table>
Put your route like this :
Route::get('service/search', 'ServiceController#search')->name('live_search.action');
Route::resource('service', 'ServiceController');
After that open the Browser Console panel (Press F12 to open it) and check the Ajax request in Network tab.
Where you can get the specific error if any in the Response tab.
If you need an extra route to your resource route,you should place the new route before the resource route.
Route::get('service/search', 'ServiceController#search')->name('live_search.action');
Route::resource('service', 'ServiceController');
i've just started learning Jplugin development, so here i made a little voting script. Everything here works fine, but i want conf.php file to be made in joomla framework style. As you see here, 1 and 2 files works perfectly together. I want to use third example instead of second, in which i use simple php code. The last example i tried to do is using joomla framework, but it doesnt work. I have no idea what's wrong with that code. Anyone see could tell where I made a mistake or maybe far away from doing it right ?
<?php
defined( '_JEXEC' ) or die;
?>
<?php
class plgSystemRatingx extends JPlugin
{
public function onContentBeforeDisplay()
{
?>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".like").click(function()
{
var id=$(this).attr("id");
var name=$(this).attr("name");
var dataString = 'id='+ id + '&name='+ name;
$("#votebox").slideDown("slow");
$("#flash").fadeIn("slow");
$.ajax
({
type: "POST",
url: "conf.php",
data: dataString,
cache: false,
success: function(html)
{
$("#flash").fadeOut("slow");
$("#content").html(html);
}
});
});
$(".close").click(function()
{
$("#votebox").slideUp("slow");
});
});
</script>
<body>
<div style="margin:50px">
Like -- Dislike
<div id="votebox">
<span id='close'>X</span>
<div style="height:13px">
<div id="flash">Loading........</div>
</div>
<div id="content">
</div>
</div>
</div>
<?php
return true;
}
}
this piece of code works perfectly
<?php
$mysql_hostname = "localhost";
$mysql_user = "px";
$mysql_password = "px";
$mysql_database = "jum";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password)
or die("Opps some thing went wrong");
mysql_select_db($mysql_database, $bd) or die("Opps some thing went wrong");
if($_POST['id'])
{
$id=mysql_real_escape_string($_POST['id']);
$name=mysql_real_escape_string($_POST['name']);
mysql_query("update messages set $name=$name+1 where id='$id'");
$result=mysql_query("select up,down from messages where id='$id'");
$row=mysql_fetch_array($result);
$up_value=$row['up'];
$down_value=$row['down'];
$total=$up_value+$down_value;
$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;
?>
<div style="margin-bottom:10px">
<b>Ratings for this blog</b> ( <?php echo $total; ?> total)
</div>
<table width="700px">
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $up_value; ?></td>
<td width="600px"><div id="greebar" style="width:<?php echo $up_per; ?>%"></div></td>
</tr>
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $down_value; ?></td>
<td width="600px"><div id="redbar" style="width:<?php echo $down_per; ?>%"></div></td>
</tr>
</table>
<?php
}
?>
and this made in joomla style doesnt work at all
<?php
defined( '_JEXEC' ) or die;
?>
<?php
if(JRequest::getVar('id'))
{
$id = JRequest::getInt('id');
$name = JRequest::getInt('name');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query2 = $db->getQuery(true);
$queryup = $db->getQuery(true);
$querydown = $db->getQuery(true);
$query->update('messages');
$query->set("message = 1");
$query->where("id = $id");
$query2->select('up,down');
$query2->from('messages');
$query2->where("id = $id");
$queryup->select('up');
$queryup->from('messages');
$queryup->where("id = $id");
$querydown->select('down');
$querydown->from('messages');
$querydown->where("id = $id");
$db->setQuery( $query );
$db->query();
$db->setQuery( $query2 );
$db->query();
$db->setQuery( $queryup );
$data0 = $db->query();
$db->setQuery( $querydown );
$data1 = $db->query();
$up_value= $db->insertid($data0);;
$down_value = $db->insertid($data1);
$total=$up_value+$down_value;
$up_per=($up_value*100)/$total;
$down_per=($down_value*100)/$total;
?>
<table width="700px">
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $up_value; ?></td>
<td width="600px"><div id="greebar" style="width:<?php echo $up_per; ?>%"></div></td>
</tr>
<tr>
<td width="30px"></td>
<td width="60px"><?php echo $down_value; ?></td>
<td width="600px"><div id="redbar" style="width:<?php echo $down_per; ?>%"></div></td>
</tr>
</table>
<?php
}
Try this
$query->where('id = ' . $db->qn($id));
etc