davy_yg

davy_yg

Member Since 2 Years Ago

Jakarta

Experience Points
89,880
Total
Experience

120 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
439
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 18
89,880 XP
Jan
22
5 days ago
Activity icon

Started a new Conversation Vue Template

In vue videos I found:

<template v-slot:footer>
    <a href="#">Cancel</a>
</template>

What does it means. I thought vue template should be the name of the vue file such as:

<footer>

</footer>

ref: https://vuejs.org/v2/guide/components-slots.html

Activity icon

Replied to Redis

So even if you use redis, you still need to use both redis and the normal db?

Activity icon

Replied to Redis

I watched the first 6 videos:

https://laracasts.com/series/learn-laravel-and-redis-through-examples/episodes/6

So can you use redis and still use the database sql at the same times? I mean redis is not a replacement of the database right?

You can increment value by video++; for example right?

If it is not holding database data then why compare it with databases:

" Its held in memory on the server and therefore MUCH faster than getting the value from the database, incrementing it and writing it back."

Activity icon

Replied to Redis

So if you use redis then you don't use sql syntax any longer?

Activity icon

Replied to Redis

So what's the point of using Redis if it only incrementing it. Laravel could do that also?

I thought redis is cachable tools for database to save queries if cache them. For the same query could be use over2 so you could cache it so that only 1 query remains. Is this possible with redis?

Activity icon

Started a new Conversation Redis

I am in the middle of watching redis videos:

<?php

Route::get('videos/{id}', function ($id) {


    $downloads = Redis::get("videos.{$id}.downloads");

    return view('welcome')->withDownloads($downloads);

});

Route::get('videos/{id}/downloads', function ($id) {

// Prepare the download

Redis::incr("videos.{$id}.downloads");

});


?>

Does it means put into cache everything that is after Redis::

?

ref: http://redis.io

Jan
21
6 days ago
Activity icon

Started a new Conversation Dual Bootable Option Disappeared

I installed two OS on my laptop the first one is Win 10 and the second one is ubuntu.

Normally, I have two options that I have to pick in order to enter. After, a while it started to disappeared and automatically carry me to ubuntu OS. I have to manually press F12 repeatedly to get the bootable option.

Any clue why?

ref: https://superuser.com/questions/1289741/dual-boot-ubuntu-disappeared

Jan
20
1 week ago
Activity icon

Awarded Best Reply on Npm Error

Solved after doing the last link repeatedly.

and run:

npm install npm run dev

Activity icon

Replied to Npm Error

Solved after doing the last link repeatedly.

and run:

npm install npm run dev

Activity icon

Started a new Conversation Npm Error

D:\xampp72\htdocs\sesa_master2\sesa-e-commerce>npm i

npm ERR! code ETIMEDOUT npm ERR! errno ETIMEDOUT npm ERR! network request to https://registry.npmjs.org/@babel/plugin-transform-new-target/-/plugin-transform-new-target-7.4.4.tgz failed, reason: connect ETIMEDOUT 13.250.177.223:8080 npm ERR! network This is a problem related to network connectivity. npm ERR! network In most cases you are behind a proxy or have bad network settings. npm ERR! network npm ERR! network If you are behind a proxy, please make sure that the npm ERR! network 'proxy' config is set properly. See: 'npm help config'

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\Admin\AppData\Roaming\npm-cache_logs\2020-01-20T13_55_07_302Z-debug.log

I already turn off my windows firewall and anvirus. but still wonder why this error still appears?

ref: https://github.com/npm/npm/issues/17064

https://luxiyalu.com/how-to-remove-all-npm-proxy-settings/

Activity icon

Started a new Conversation Gitlab

I am trying to push a new file to gitlab and get the following message:

git.exe push --progress "https://gitlab.com/davy_yg/sesa_master.git" master
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://gitlab.com/davy_yg/sesa_master.git/'


git did not exit cleanly (exit code 128) (2218 ms @ 1/20/2020 1:21:33 PM)

Any clue why?

ref: https://gitlab.com/gitlab-com/support-forum/issues/980

Where to enter username and password?

Activity icon

Replied to Call To A Member Function ProductReview() On Null

If I put Product in front of $product:

Argument 1 passed to App\CacheableRepositories\ProductCatalogRepository::getRating() must be an instance of App\CacheableRepositories\Product, null given, called in F:\xampp\htdocs\sesa_master3\sesa-e-commerce\app\CacheableRepositories\ProductCatalogRepository.php on line 376

$product is a part of the query. It's someone else code, I have trace it where it all comes from.

Activity icon

Started a new Conversation Call To A Member Function ProductReview() On Null

I get the following error:

Call to a member function productReview() on null

   public function getRating($product)
    {
    $rating = ($product->productReview()->count('rating')) ?
    $product->productReview()->sum('rating') / $product->productReview()->count('rating') :
    0;
        return number_format($rating, '1', ',', '');
    }

this line is being highlighted $rating = ($product->productReview()->count('rating')) ?

Any clue why? Is the logic correct? If it is null then print 0?

Activity icon

Started a new Conversation Cannot Read Where Translation Description

For some reason why I cannot see the result of these:

HomeController.php

public function __construct(RepoProduct $productRepo, HomeRepository $homeRepo, ProductInvRepo $productInvRepo)
{
    ...
$this->productCatalogRepo = \Cacheable::wrap(ProductCatalogRepository::class);
...
}

   public function search(Request $request)
    {
...

$products = $this->productCatalogRepo->getProductsByFilter(
        $flag,
        $keyword,
        $benefit,
        $format,
        $page,
        $perPage,
        $sortBy
    );

ProductCatalogRepository.php

public function getProductsByFilter(
    $flag,
    $keyword = null,
    $benefit = null,
    $format = null,
    $page = null,
    $perPage = null,
    $sortBy = null
    
) {
    
if ($perPage == null) {
        $perPage = 12;
    }

    $productCatalog = $this->model::has('price')
        ->where('is_archive', StatusProductEnum::ARCHIVE)
        ->with(array_merge(['benefitSpecific', 'dataFormat'], $this->defaultAppends));

    if ($keyword) {

   // dd($keyword)
        $productCatalog = $productCatalog
                                 ->whereTranslationLike('name', '%' . $keyword . '%')
                                 ->orWhereTranslationLike('description', '%' . $keyword . '%');
    }

WhereTranslationLike description is not read. I can pulled out the dd($keyword) info. but that long description I cannot pull like the products that matches a part of the description.

I find out that the search result to be inaccurate after adding:

->orWhereTranslationLike('description', '%' . $keyword . '%');
Jan
19
1 week ago
Activity icon

Started a new Conversation Git Stash

When I tried to git stash back to my previous commit I get the following message:

[email protected] MINGW64 /f/xampp/htdocs/sesa_master3/sesa-e-commerce (sesa_davy)
$ git stash

No local changes to save

Any clue what it means?

Activity icon

Replied to Code Quality Check

I don't know which config. Is it this one:

https://drive.google.com/file/d/1Gb6_G5FIAPHm4AqZk4GX89NC3pTymxWq/view?usp=sharing

I never changed the gitlab it is the old gitlab that I normally used suddenly the error appears.

Activity icon

Started a new Conversation Code Quality Check

For some reason upon code quality check in github I get this kind of message:

Created cache
ERROR: Job failed (system failure): Error response from daemon: get     e0ec3350ec5694cd281f21e423b72bcc6a4037718ff2459531500355e4fefd81: database not open         (executor_docker.go:743:0s)

Any clue what it means?

ref: https://gitlab.com/gitlab-com/support-forum/issues/3864

How to do this things:

Done two workaround and seems to be working. But the workaround is not good and cant do everyday.

    Stop the docker service
    Remove all the images
    Free up the space
    Restart the docker and runner services

ref: https://docs.gitlab.com/runner/install/docker.html

Jan
18
1 week ago
Activity icon

Replied to Git Error RPC Failed; Curl 56 OpenSSL SSL_read: Connection Was Reset

I tested my internet connection with speedtest.net

Download 23.98 Mbps

Upload 29.20 Mbps

I don't think that is the issue. Yet, I already tried to clone repeatedly and it does not works. A long time ago it works just fine.

Activity icon

Replied to Optimize Codes

ProductCatalogRepository.php

        if ($sortBy != null) {
        $sortingDirection = '';
        if ($sortBy == SortingOptionEnum::LOWESTPRICE) ? $sortingDirection = 'asc' : $sortingDerietion = 'desc'; 
        {
            $pct = 'product_category_translations as t';
                $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->groupBy('product_catalogs.id')
                    ->orderBy('ppl.price', $sortingDirection)
                    ->select('product_catalogs.*');
        }

syntax error, unexpected '?'

Activity icon

Started a new Conversation Git Error RPC Failed; Curl 56 OpenSSL SSL_read: Connection Was Reset

Hello when trying to download git I failed.

[email protected] MINGW64 /f/xampp/htdocs/sesa_master2
$ git init
Initialized empty Git repository in F:/xampp/htdocs/sesa_master2/.git/

[email protected] MINGW64 /f/xampp/htdocs/sesa_master2 (master)
$ git config http.postBuffer 524288000

[email protected] MINGW64 /f/xampp/htdocs/sesa_master2 (master)
$ git clone https://gitlab.com/suitmedia/sesa-e-commerce.git
Cloning into 'sesa-e-commerce'...
remote: Enumerating objects: 6327, done.
remote: Counting objects: 100% (6327/6327), done.
remote: Compressing objects: 100% (2543/2543), done.
Receiving objects:  54% (3453/6327), 1.71 MiB | 225.00 KiB/s
error: RPC failed; curl 56 OpenSSL SSL_read: Connection was reset
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

ref: https://stackoverflow.com/questions/46232906/git-clone-error-rpc-failed-curl-56-openssl-ssl-read-ssl-error-syscall-errno

I also tried this:

[email protected] MINGW64 /f/xampp/htdocs/sesa_master2 (master)
$ git config --global http.postBuffer 524288000

[email protected] MINGW64 /f/xampp/htdocs/sesa_master2 (master)
$ git clone https://gitlab.com/suitmedia/sesa-e-commerce.git
Cloning into 'sesa-e-commerce'...
remote: Enumerating objects: 6327, done.
remote: Counting objects: 100% (6327/6327), done.
remote: Compressing objects: 100% (2543/2543), done.
error: RPC failed; curl 56 OpenSSL SSL_read: Connection was reset
fatal: the remote end hung up unexpectedly
fatal: early EOF
fatal: index-pack failed

It also shows the same error message.

Any clue why?

Jan
17
1 week ago
Activity icon

Started a new Conversation Optimize Codes

We are using Laravel debuging codes that could count the query in the bottom.

ProductCatalogRepository.php

public function getProdByRange($range, $category, $page, $perPage, $sortBy, $brandRequest)

` { $perPage = $perPage ?: 12;

    $products = $this->model::has('price')
        ->with(array_merge($this->defaultAppends, ['benefitSpecific', 'dataFormat', 'price.productInventory']))
        ->where('is_archive', StatusProductEnum::ARCHIVE);

    if ($category->hasChild()) {
        $categoryIds = $category->getAllChilds(['*', 1])->pluck('id')->toArray();

        $products = $products->whereHas('productCategories', function ($query) use ($categoryIds) {
            $query->whereIn('product_category_id', $categoryIds);
        });
    } else {
        $products = $products->whereHas('productCategories', function ($query) use ($category) {
            $query->where('product_category_id', $category->id);
        });
    }

    if ($brandRequest != null && $brandRequest != 'All Brand') {
        $products->where('brand_id', $brandRequest);
    }

    if ($sortBy == null || $sortBy == SortingOptionEnum::FRESHNESS) {
            $products = $products
                 ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                 ->join('product_category_translations as t', 't.product_category_id', '=', 'c.product_category_id')
                 ->where('t.name', $range)
                 ->orderBy('freshness')
                 ->select('product_catalogs.*');
    }

    if ($sortBy != null) {
        if ($sortBy == SortingOptionEnum::LOWESTPRICE) {
            $pct = 'product_category_translations as t';
                $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->groupBy('product_catalogs.id')
                    ->orderBy('ppl.price')
                    ->select('product_catalogs.*');
        }

        if ($sortBy == SortingOptionEnum::HIGHESTPRICE) {
            $pct = 'product_category_translations as t';
                $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->groupBy('product_catalogs.id')
                    ->orderByDesc('ppl.price')->select('product_catalogs.*');
        }
    }
    if ($perPage == 'all') {
        $perPage = $products->get()->count();
    }
    $data['products_all'] = $products->get();
    $productCatalogs = $products->paginate($perPage, ['*'], 'page', $page);

    $this->appendsAttribute($productCatalogs);
    $data['count'] = $products->count();
    $data['product'] = $productCatalogs;

    return $data;
    }

HomeController.php

    $rangeArr = [];
    $dataArr = [];

    foreach ($range as $rg) {
        array_push($dataArr, $this->productCatalogRepo->getProdByRange(
            $rg->name,
            $kategori,
            $request->page,
            $perPage,
            $request->sort_by,
            $brand ? $brand->id : null
        ));

        // get data dari range
        array_push($rangeArr, $rg->name);
    }

My codes has too many queries someone said, which could decrease the performance. After reviewing my query I still do not understand how to reduce the number of queries which could produce the same result?

Activity icon

Awarded Best Reply on Responsive

I think I figure the answer. Just like it is written:

 [class*="mobile only"]:not(.tablet),
    [class*="tablet hidden"],
    [class*="computer only"]:not(.tablet),
    [class*="large screen only"]:not(.tablet),
    [class*="widescreen only"]:not(.tablet),
    [class*="or lower hidden"]:not(.mobile)

we can choose which class to use to hide tablet hidden.

Activity icon

Replied to Responsive

I think I figure the answer. Just like it is written:

 [class*="mobile only"]:not(.tablet),
    [class*="tablet hidden"],
    [class*="computer only"]:not(.tablet),
    [class*="large screen only"]:not(.tablet),
    [class*="widescreen only"]:not(.tablet),
    [class*="or lower hidden"]:not(.mobile)

we can choose which class to use to hide tablet hidden.

Jan
16
1 week ago
Activity icon

Started a new Conversation Responsive

custom.scss

/* Tablet / iPad Portrait */    
@media only screen and (min-width: 768px) and (max-width: 991px) {
    [class*="mobile only"]:not(.tablet),
    [class*="tablet hidden"],
    [class*="computer only"]:not(.tablet),
    [class*="large screen only"]:not(.tablet),
    [class*="widescreen only"]:not(.tablet),
    [class*="or lower hidden"]:not(.mobile) {
            display: none !important;
    }
}

Hello,

What does the above code means. So if I want to write code for iPad how to reference it? using table hidden class?

Why there are so many classes which class should I use for iPad?

Jan
13
2 weeks ago
Activity icon

Started a new Conversation Magento

Hello,

For some reason, my client has a thought about moving to Magento. Yet, I heard there are a lot of limitation for Magento. Such as you cannot customize the backend.

Also, is there anyway to test the Magento software for free?

Regards, Davy

Jan
12
2 weeks ago
Activity icon

Replied to Function's Cyclomatic Complexity (12) Exceeds 10

I cancelled all the recommendation and restore it back to the original program and I finally find an example on other part of the program that works. It's the locale thing that I have to utilize.

Activity icon

Awarded Best Reply on Function's Cyclomatic Complexity (12) Exceeds 10

It finally solved. You know what? I took off the $locale thing, since we used:

https://packagist.org/packages/dimsav/laravel-translatable

I don't need to distinguish the languages. It automatically knows which language I choosed. The warning suddenly disappeared.

Activity icon

Replied to Function's Cyclomatic Complexity (12) Exceeds 10

It finally solved. You know what? I took off the $locale thing, since we used:

https://packagist.org/packages/dimsav/laravel-translatable

I don't need to distinguish the languages. It automatically knows which language I choosed. The warning suddenly disappeared.

Jan
11
2 weeks ago
Activity icon

Replied to Function's Cyclomatic Complexity (12) Exceeds 10

242 | WARNING | [ ] Function's cyclomatic complexity (11) exceeds 39 | | 10; consider refactoring the function

It does reducing the complexity. Yet, I need to reduce it by another 1 points.

Activity icon

Replied to Function's Cyclomatic Complexity (12) Exceeds 10

What about putting it into different function? Will it makes any difference? Is it because too many lines in one function ?

I don't know how to put this function in another class either?

Activity icon

Replied to Function's Cyclomatic Complexity (12) Exceeds 10

I fixed that part. This time:

  242 | WARNING | Function's cyclomatic complexity (12) exceeds 10;

39 | | consider refactoring the function

242 is this line:

public function getProdByRange($range, $category, $page, $perPage = null, $sortBy = null, $brandRequest = null)

What should I do ?

Activity icon

Replied to Function's Cyclomatic Complexity (12) Exceeds 10

It is ProductCatalogRepository.php

This is the whole function:

ProductCatalogRepository.php

public function getProdByRange($range, $category, $page, $perPage = null, $sortBy = null, $brandRequest = null)
{
    if ($perPage == null) {
        $perPage = 12;
    }
    $products = $this->model::has('price')
        ->with(array_merge($this->defaultAppends, ['benefitSpecific', 'dataFormat', 'price.productInventory']))
        ->where('is_archive', StatusProductEnum::ARCHIVE);

    if ($category->hasChild()) {
        $categoryIds = $category->getAllChilds(['*', 1])->pluck('id')->toArray();

        $products = $products->whereHas('productCategories', function ($query) use ($categoryIds) {
            $query->whereIn('product_category_id', $categoryIds);
        });
    } else {
        $products = $products->whereHas('productCategories', function ($query) use ($category) {
            $query->where('product_category_id', $category->id);
        });
    }

    if ($brandRequest != null && $brandRequest != 'All Brand') {
        $products->where('brand_id', $brandRequest);
    }

    if ($sortBy == null || $sortBy == SortingOptionEnum::FRESHNESS) {
            $locale = App::getLocale();

        if (App::isLocale('en')) {
                $products = $products
                 ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                 ->join('product_category_translations as t', 't.product_category_id', '=', 'c.product_category_id')
                 ->where('t.name', $range)
                 ->where('t.locale', 'en')
                 ->orderBy('freshness')
                 ->select('product_catalogs.*');
        } else {
            $products = $products
                 // ->join('product_categories as c', 'c.id', '=', 'product_catalogs.product_category_id')
                 ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                 ->join('product_category_translations as t', 't.product_category_id', '=', 'c.product_category_id')
                 ->where('t.name', $range)
                 ->where('t.locale', 'id')
                 ->orderBy('freshness')
                 ->select('product_catalogs.*');
        }
    }

    // dd($products->toSql());

    if ($sortBy != null) {
        if ($sortBy == SortingOptionEnum::LOWESTPRICE) {
            $locale = App::getLocale();

            $pct = 'product_category_translations as t';
            if (App::isLocale('en')) {
                    $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->where('t.locale', 'en')
                    ->groupBy('product_catalogs.id')
                    ->orderBy('ppl.price')
                    ->select('product_catalogs.*');
            } else {
                    $products = $products
                    ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                    ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                    ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                    ->where('t.name', $range)
                    ->where('t.locale', 'id')
                    ->groupBy('product_catalogs.id')
                    ->orderBy('ppl.price')
                    ->select('product_catalogs.*');
            }
        }

        if ($sortBy == SortingOptionEnum::HIGHESTPRICE) {
            $locale = App::getLocale();

            $pct = 'product_category_translations as t';
            if (App::isLocale('en')) {
                $products = $products
                ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                ->where('t.name', $range)
                ->where('t.locale', 'id')
                ->groupBy('product_catalogs.id')
                ->orderByDesc('ppl.price')->select('product_catalogs.*');
            } else {
                $products = $products
                ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                ->where('t.name', $range)
                ->where('t.locale', 'id')
                ->groupBy('product_catalogs.id')
                ->orderByDesc('ppl.price')->select('product_catalogs.*');
            }
        }
    }
    if ($perPage == 'all') {
        $perPage = $products->get()->count();
    }

    // dd($products->toSql());

    $data['products_all'] = $products->get();
    $productCatalogs = $products->paginate($perPage, ['*'], 'page', $page);

    $this->appendsAttribute($productCatalogs);
    $data['count'] = $products->count();
    $data['product'] = $productCatalogs;

    // dd($data['product']);

    return $data;
}

Should I move the some of the if statement to different functions? which part?

Activity icon

Replied to Function's Cyclomatic Complexity (12) Exceeds 10

I don't know what else to do:

if ($sortBy == SortingOptionEnum::HIGHESTPRICE) {
            $locale = App::getLocale();

            $pct = 'product_category_translations as t';
            if (App::isLocale('en')) {
                $products = $products
                ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                ->where('t.name', $range)
                ->where('t.locale', 'id')
                ->groupBy('product_catalogs.id')
                ->orderByDesc('ppl.price')->select('product_catalogs.*');
            } else {
                $products = $products
                ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                ->where('t.name', $range)
                ->where('t.locale', 'id')
                ->groupBy('product_catalogs.id')
                ->orderByDesc('ppl.price')->select('product_catalogs.*');
            }
        }

If I changed my codes, I must not changed the meanings.

Activity icon

Started a new Conversation Function's Cyclomatic Complexity (12) Exceeds 10

I get code quality test mentioning:

  242 | WARNING | Function's cyclomatic complexity (12) exceeds 10;

39 | | consider refactoring the function

    $pct = 'product_category_translations as t';
            if (App::isLocale('en')) {
                $products = $products
                ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                ->where('t.name', $range)
                ->where('t.locale', 'id')
                ->groupBy('product_catalogs.id')
                ->orderByDesc('ppl.price')->select('product_catalogs.*');
            } else {
                $products = $products
                ->join('product_price_lists as ppl', 'ppl.product_catalog_id', '=', 'product_catalogs.id')
                ->join('product_catalog_product_category as c', 'c.product_catalog_id', 'product_catalogs.id')
                ->join($pct, 't.product_category_id', '=', 'c.product_category_id')
                ->where('t.name', $range)
                ->where('t.locale', 'id')
                ->groupBy('product_catalogs.id')
                ->orderByDesc('ppl.price')->select('product_catalogs.*');
            }

line 242 is the last closing bracket: }

ref: https://phpmd.org/rules/codesize.html

I still don't understand how to fix the warning?

Activity icon

Started a new Conversation Git Error

Hello,

I am experiencing this git error. I accidently type git commit . then close my git bash. Then, when I try to git add . and git commit I get the following error. How to fix it?

[email protected] MINGW64 /f/xampp/htdocs/sesa_master3/sesa-e-commerce (sesa_davy) $ git add . fatal: Unable to create 'F:/xampp/htdocs/sesa_master3/sesa-e-commerce/.git/index.lock': File exists.

Another git process seems to be running in this repository, e.g. an editor opened by 'git commit'. Please make sure all processes are terminated then try again. If it still fails, a git process may have crashed in this repository earlier: remove the file manually to continue.

Jan
10
2 weeks ago
Activity icon

Replied to Sync

I have a table named product_catalog_product_category . So it automatically creates this new table whenever I used sync?

Activity icon

Replied to Sync

Will that new table exist in my database?

So it doesn't save product_category_id ?

Activity icon

Replied to Sync

By viewing my codes what is the name of the intermediate table?

Activity icon

Started a new Conversation Sync

I don't understand this line of codes:

ProductCatalogsRespository.php

$ids[] = $request->product_category_id;
    if (strpos($request->product_category_id, ',')) {
        $ids = explode(',', $request->product_category_id);
    }
    $productCatagoryId = array_unique($ids);
    $productCatalog->productCategories()->sync($ids);

    $this->uploadFile($productCatalog, $request->all(), 'media');
    $this->uploadFile($productCatalog, $request->all(), 'nutrition');
    $this->uploadFile($productCatalog, $request, 'certificate');

ref: https://laravel.com/docs/5.8/eloquent-relationships

"The sync method accepts an array of IDs to place on the intermediate table"

What is intermediate table? There is many to many relationship here.

This part also confusing: if (strpos($request->product_category_id, ',')) {

ref: https://www.php.net/manual/en/function.strpos.php

Is it to tell us the position of the coma ","?

Jan
09
2 weeks ago
Activity icon

Started a new Conversation Using ToSql()

Method Illuminate\Database\Eloquent\Collection::toSql does not exist

 $range = ProductCategory::whereIn('id', $categoryIds)
                        ->translatedIn('en')->get();      

 dd($range->toSql());

I want to see the result of the sql but unable to do so. Even after I delete the ->get(); still does not works.

ref: http://mydoubts.in/blog/tag/tosql-not-working-in-laravel/

Any clue why?

Activity icon

Replied to Invalid Argument Supplied For Foreach()

I thought it's fixed. I get this error:

dd($range);

    foreach ($range as $rg) {
        array_push($dataArr, $this->productCatalogRepo->getProdByRange(
            $rg->name,
            $kategori,
            $request->page,
            $perPage,
            $request->sort_by,
            $brand ? $brand->id : null
        ));

        // get data dari subtitle
        array_push($rangeArr, $range->name);
    }

dd($range) result:

    Collection {#5756 ▼
     #items: array:8 [▼
    0 => ProductCatalog {#5867 ▼
    +translatedAttributes: array:14 [▶]
    #guarded: []
    #searchableColumns: array:14 [▶]
     #appends: array:1 [▶]
    #connection: "mysql"
    #table: "product_catalogs"
    #primaryKey: "id"
    #keyType: "int"
    +incrementing: true
    #with: []
    #withCount: []
    #perPage: 15
    +exists: true
    +wasRecentlyCreated: false
    #attributes: array:1 [▼
     "name" => "Sayuran"
    ]
    #original: array:1 [▶]
    #changes: []

name does exist. Why it mentions it doesn't exist?

Activity icon

Replied to Invalid Argument Supplied For Foreach()

Thanks I get that part done. I already fixed it.

Activity icon

Replied to Invalid Argument Supplied For Foreach()

ErrorException thrown with message "Invalid argument supplied for foreach()"

Stacktrace: #68 ErrorException in F:\xampp\htdocs\sesa_master3\sesa-e-commerce\app\Http\Controllers\HomeController.php:402 #67 Sentry\ErrorHandler:handleError in F:\xampp\htdocs\sesa_master3\sesa-e-commerce\app\Http\Controllers\HomeController.php:402 #66 App\Http\Controllers\HomeController:filter in F:\xampp\htdocs\sesa_master3\sesa-e-commerce\vendor\laravel\framework\src\Illuminate\Routing\Controller.php:54 ...

Activity icon

Replied to Invalid Argument Supplied For Foreach()

I still get the same error:

        foreach ($range as $rg) {
        array_push($dataArr, $this->productCatalogRepo->getProdByRange(
            $rg->name,
            $kategori,
            $request->page,
            $perPage,
            $request->sort_by,
            $brand ? $brand->id : null
        ));

        // get data dari subtitle
        array_push($rangeArr, $range->name);
    }