Error Collection::appends does not exist In pagination with mapping - laravel-5

In my Laravel 5.8 app I have database request with mapping, like:
$paymentItems = PaymentItem
::getByStatus('C', 'payments')
->select(
$this->payment_items_tb . '.*',
$this->downloads_tb . '.title as payed_item_title',
$this->users_tb . '.username as payment_username',
$this->payments_tb . '.payment_type',
...
$this->payments_tb . '.payer_shipping_address'
)
->orderBy($this->payment_items_tb . '.created_at', 'desc')
->join($this->payments_tb, $this->payments_tb . '.id', '=', $this->payment_items_tb . '.payment_id')
->join($this->users_tb, $this->users_tb . '.id', '=', $this->payments_tb . '.user_id')
->join($this->downloads_tb, $this->downloads_tb . '.id', '=', $this->payment_items_tb . '.item_id')
->get()
->map(function ($item) {
return [
'id' => $item->id,
'total' => $item->price * $item->quantity,
....
'payment_type_label' => Payment::getPaymentTypeLabel($item->payment_type),
];
});
It worked ok for me untill I decided to remake this listing as pagination, like:
$paymentItems = PaymentItem
::getByStatus('C', 'payments')
->select(
$this->payment_items_tb . '.*',
$this->downloads_tb . '.title as payed_item_title',
$this->users_tb . '.username as payment_username',
$this->payments_tb . '.payment_type',
...
$this->payments_tb . '.payer_shipping_address'
)
->orderBy($this->payment_items_tb . '.created_at', 'desc')
->join($this->payments_tb, $this->payments_tb . '.id', '=', $this->payment_items_tb . '.payment_id')
->join($this->users_tb, $this->users_tb . '.id', '=', $this->payments_tb . '.user_id')
->join($this->downloads_tb, $this->downloads_tb . '.id', '=', $this->payment_items_tb . '.item_id')
->paginate($ref_items_per_pagination, null, null, $page)
->onEachSide((int)($ref_items_per_pagination / 2))
->map(function ($item) {
return [
'id' => $item->id,
'total' => $item->price * $item->quantity,
...
'payment_type_label' => Payment::getPaymentTypeLabel($item->payment_type),
];
});
But In my blade template I got error :
Method Illuminate\Support\Collection::appends does not exist. (View: /resources/views/defaultBS41Backend/admin/dashboard/payments_rows.blade.php) {"userId":5,"exception":"[object] (ErrorException(code: 0): Method Illuminate\\Support\\Collection::appends does not exist. (View: /resources/views/defaultBS41Backend/admin/dashboard/payments_rows.blade.php) at /vendor/laravel/framework/src/Illuminate/Support/Traits/Macroable.php:102, BadMethodCallException(code: 0): Method Illuminate\\Support\\Collection::appends does not exist.
trying to show pagination links block:
<div class="row">
{{ $paymentItems->appends([])->links() }}
<input type="button" class="btn btn-primary" value="Refresh" onclick="javascript:backendDashboard.showPaymentsRows(1); return false;">
</div>
Is there is a way to fix this error and to show paginations links ?

Related

Problem with generate multiple file mPDF codeigniter

Hello guys i'm a little bit confuse with my mpdf function in codeigniter to generate multiple file pdf, i tried to research and nothing can solve this is issue,
i have anchor that action to download function, and the idea is to call all function with mpdf generate in it. here is the code :
public function download($id)
{
$this->kehadiranDosen($id);
$this->nilaiSeminar($id);
$this->beritaAcara($id);
}
function beritaAcara($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Berita Acara
$html = $this->load->view('seminar/beritaAcara', $data, true);
$this->load->library('M_pdf');
$mpdf = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf->WriteHTML($html);
$mpdf->Output('BERITA ACARA,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf);
unset($html);
}
function kehadiranDosen($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Kehadiran Dosen
$html2 = $this->load->view('seminar/kehadiranDosen', $data, true);
$this->load->library('M_pdf');
$mpdf2 = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf2->WriteHTML($html2);
$mpdf2->Output('KEHADIRAN DOSEN,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf2);
unset($html2);
}
function nilaiSeminar($id)
{
$data['peserta'] = $this->db->get_where('seminar', ['id' => $id])->row_array();
//Nilai Seminar
$html3 = $this->load->view('seminar/nilaiSeminar', $data, true);
$this->load->library('M_pdf');
$mpdf3 = $this->m_pdf->load([
'mode' => 'utf-8',
'format' => 'A4'
]);
$mpdf3->WriteHTML($html3);
$mpdf3->Output('NILAI SEMINAR,' . ucfirst($data['peserta']['nama']) . ',' . $data['peserta']['npm'] . '.pdf', "I");
unset($mpdf3);
unset($html3);
}
and when i click it, only kehadiran dosen generated, anyone can solve this? thank you so much before

laravel livewire intervention images

I am trying to use Intervention image with Livewire to reduce the sizes and I am not succeeding. They can guide me or tell me if Livewire may not allow it.
I am trying to pass this methodology:
foreach ($this->imagenes as $pathGaleria) {
$imgUrl = $pathGaleria->store('imagenesPropiedades');
$img = imgPropiedades::create([
'url' => $imgUrl,
'property_id' => $this->propiedadId
]);
to this other way:
foreach ($this->imagenes as $pathGaleria) {
$imgUrl = $pathGaleria->store('imagenesPropiedades');
Image::make($pathGaleria)->resize(1200, null, function ($constraint) {
$constraint->aspectRatio();
})
->save($imgUrl);
$img = imgPropiedades::create([
'url' => $imgUrl,
'property_id' => $this->propiedadId
]);
}
but the page remains blank. Thank you.
I found this today, may work for you
https://gist.github.com/daugaard47/659984245d31b895d00ee5dcbdee44ec
+
$images = Collection::wrap($request->file('file'));
$images->each(function ($image) use ($id) {
$basename = Str::random();
$original = $basename . '.' . $image->getClientOriginalExtension();
$thumbnail = $basename . '_thumb.' . $image->getClientOriginalExtension();
ImageManager::make($image)
->fit(250, 250)
->save(public_path('/images/' . $thumbnail));
$image->move(public_path('/images/'), $original);
Model::create([
]);
});

Laravel Homestead Development: AJAX POST request gets redirected for unknown reason

I'm on Laravel 5.3 and I was working on a form I POST submit to the server. What I want to point out right at the beginning is that I have been working on this form for days, with no issues what so ever. Yesterday I was working in the store method of my controller, when all of a sudden the form won't submit at all anymore.
The opening form:
{!! Form::model($addon = new \App\Addon, ['name' => 'FinalForm', 'route' => 'addons.store', 'enctype' => 'multipart/form-data']) !!}
My route:
Route::resource('addons', 'AddonController');
php artisan route:list:
Method: POST
URI: addons
Name: addons.store
Action: App\Http\Controllers\AddonController#store
Middleware: web,auth
So what happens now is, the form gets posted, but then, for some reason, get's redirected. This is what chrome says:
POST request to /addons
And after that, for some reason, GET request to /addons/
As you can see I'm getting a 403 Forbidden response. Why is the request being redicted to /addons/ ??
As I said before, I changed NOTHING, I was working with the inner logic of the store method on the controller when this popped up. I even restarted the homestead box (and my whole machine), I don't know what is causing it.
EDIT (controller):
/**
* Store the addon.
*
* #return Response
**/
public function store(CreateAddonRequest $request, ImageHandler $imageHandler)
{
$input = $request->only('title', 'body', 'author', 'slogan', 'version', 'revision', 'published_at', '_img_data');
$session = $request->session()->all();
$slug = SlugService::createSlug(Addon::class, 'title', $input['title'], ['unique' => true]);
$imageHandler->move($slug, $input['body'], 'description');
$body = $imageHandler->body;
$addon = Auth::user()->addons()->create([
'body' => $body,
'title' => $input['title'],
'slogan' => $input['slogan'],
'author' => $input['author'],
'locales' => $session['locales'],
'published_at' => $input['published_at']
]);
$addon->categories()->attach($request->input('categories'));
Storage::makeDirectory('addons/' . $slug . '/files/');
$extension = Dir::extension('temp/' . $session['file_name']);
if ($input['revision'] != "") {
$file = $addon->slug . '-v' . $input['version'] . '-r' . $input['revision'] . '.' . $extension;
} else {
$file = $addon->slug . '-v' . $input['version'] . '.' . $extension;
}
Storage::disk('local')->move('temp/' . $session['file_name'], 'public/addons/' . $addon->slug . '/files/' . $file);
// With 5.4 we don't need that check anymore
if ($input['revision'] == "") {
$input['revision'] = null;
}
$addon->files()->create([
'file_name' => $file,
'hash' => $session['hash'],
'version' => $input['version'],
'revision' => $input['revision'],
'game_version' => $session['interface'],
'virustotal' => $session['virustotal']
]);
dd('done');
// if ($request->hasFile('images'))
// {
// Storage::makeDirectory('addons/' . $slug . '/images/');
// foreach ($request->file('images') as $image)
// {
// $imageName = uniqid() . '.' . $image->getClientOriginalExtension();
// //$image->storeAs('addons/' . $slug . '/images/', $imageName);
// $addon->images()->create(array('image_name' => $imageName));
// }
// }
// flash('The addon has been uploaded.');
// return redirect('addons');
dd('done');
return response()->json([
'success' => true,
'message' => 'Images checked',
]);
}

logging all queries after execution in codeigniter

i want to log all queries after execution using hooks.
-i enabled hooks in config.php
-this is my hook-->
$hook['post_controller'] = array(
'class' => 'Db_log',
'function' => 'logQueries',
'filename' => 'db_log.php',
'filepath' => 'hooks'
);
-and this is hook defination-->
class Db_log
{
function __construct()
{
}
function logQueries()
{
$CI = & get_instance();
$filepath = APPPATH . 'logs/Query-log-' . date('Y-m-d') . '.php';
$handle = fopen($filepath, "a+");
$times = $CI->db->query_times;
foreach ($CI->db->queries as $key => $query)
{
$sql = $query . " \n Execution Time:" . $times[$key];
fwrite($handle, $sql . "\n\n");
}
fclose($handle);
}
}
--its creating query_log file
--but no records of queries being stored
Your Code looks fine - the only reason why this doesn't work is in your DB Configuration - take a look #your DB Connection in the database.php under application/config/
There is an option "save_queries" which should be set to true
$db['default'] = array(
...
'save_queries' => TRUE
);
For me it only worked when I define de $hook array in config/hooks.php .

wordpress display image caption if possible, but only on post page

I'm trying to make a function I can put into my functions.php that controls the images placed on each post's page. I want any image that has a caption to have that caption display under the image with paragraph tags.
Try this:
function img_caption_only_in_posts( $current_html, $attr, $content ) {
global $post;
extract(shortcode_atts(array(
'id' => '',
'align' => 'alignnone',
'width' => '',
'caption' => ''
), $attr));
if ( 1 > (int) $width || empty($caption) )
return $content;
if ($post->post_type=='page')
$caption="";
if ( $id ) $id = 'id="' . esc_attr($id) . '" ';
return '<div ' . $id . 'class="wp-caption ' . esc_attr($align) . '" style="width: ' . (10 + (int) $width) . 'px">'
. do_shortcode( $content ) . '<p class="wp-caption-text">' . $caption . '</p></div>';
}
add_filter( 'img_caption_shortcode', 'img_caption_only_in_posts',10,3 );
I borrowed the code from this answer and added the code for checking if the post is page or not.

Resources