apakah ini termasuk dalam N+1 problem laravel..? saya mengalami pelambatan pada website

Screenshot (9)_LI.jpg

berikut saya lampirkan code service providernya

<?php

namespace App\Providers;

use App\General;
use App\Pesanan;
use App\ViewPesanan;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\View;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        require_once app_path('Helpers/Swal.php');
        require_once app_path('Helpers/Formatter.php');
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        View::composer('*', function ($view) {
            $appName = config('app.name');

            if (preg_match_all('/\b(\w)/', strtoupper($appName), $value))
                $acronymAppName = implode('', $value[1]);

            $view
                ->with('appName', $appName)
                ->with('acronymAppName', $acronymAppName);

            if (strpos(url()->current(), 'admin') !== false && strpos(url()->current(), 'print') === false) {
                $logo = General::where('type', 'logo')->first();
                $path = $logo->content;

                $unprocessedPesanan = ViewPesanan::whereNotIn('status_pesanan_id', [
                    Pesanan::STATUS_SELESAI,
                    Pesanan::STATUS_DIBATALKAN
                ])
                    ->groupBy('status_pesanan_id')
                    ->get([
                        'status_pesanan_id',
                        DB::raw("SUM(1) as total")
                    ])
                    ->pluck('total', 'status_pesanan_id');

                $totalUnprocessedPesanan = $unprocessedPesanan->sum();

                $view
                    ->with('logo', $path)
                    ->with('unprocessedPesanan', $unprocessedPesanan)
                    ->with('totalUnprocessedPesanan', $totalUnprocessedPesanan);
            }

            if (strpos(url()->current(), 'admin') === false) {
                $unreadPesanan = ViewPesanan::where('pelanggan_id', Auth::id())
                    ->whereNull('read_at')
                    ->groupBy('status_pesanan_id')
                    ->get([
                        'status_pesanan_id',
                        DB::raw("SUM(1) as total")
                    ])
                    ->pluck('total', 'status_pesanan_id');

                $totalUnreadPesanan = $unreadPesanan->sum();

                $view
                    ->with('unreadPesanan', $unreadPesanan)
                    ->with('totalUnreadPesanan', $totalUnreadPesanan);
            }

            if (strpos(url()->current(), 'print') !== false) {
                $alamat = General::where('type', 'alamat')->first()->content;
                $telepon = General::where('type', 'telepon')->first()->content;

                $view
                    ->with('alamat', $alamat)
                    ->with('telepon', $telepon);
            }
        });
    }
}

avatar Ja9090
@Ja9090

3 Kontribusi 0 Poin

Dipost 2 tahun yang lalu

Belum ada Jawaban. Jadi yang pertama Jawaban

Login untuk ikut Jawaban