Random Product instead of related

Posted In Introductions
  • cbmagent-agent 1 year ago
    Hi there, I was wondering if there was a simple code change we can make on product/read.blade.php that can instead just grab # of random products to place instead of 'related products', so i can ignore adding related products from the admin? It will just populate those related products with randomly selected products from the database from the amount I choose. (3 or 4 etc)?
    
    Really great to know, and I have replied on old topics here, does it alert or should I just remake threads to bring attention to them.  
    
    Thanks again!

    Hi there, I was wondering if there was a simple code change we can make on product/read.blade.php that can instead just grab # of random products to place instead of 'related products', so i can ignore adding related products from the admin? It will just populate those related products with randomly selected products from the database from the amount I choose. (3 or 4 etc)?

    Really great to know, and I have replied on old topics here, does it alert or should I just remake threads to bring attention to them.

    Thanks again!

  • mark 1 year ago
    You can grab 4 random products using this code:
    
    ```
    @php
        $randomProducts = \App\Product::orderBy(DB::raw('RAND()'))->get();
    @endphp
    ```
    
    Hope that helps.
    
    NOTE: This might not work for different SQL types.

    You can grab 4 random products using this code:

    @php
        $randomProducts = \App\Product::orderBy(DB::raw('RAND()'))->get();
    @endphp
    

    Hope that helps.

    NOTE: This might not work for different SQL types.

  • cbmagent-agent 1 year ago
    Thanks, Mark I sent you an emai also

    Thanks, Mark I sent you an emai also

  • mark 1 year ago
    I currently have a lot of emails on my inbox.
    If I haven't got back to you by tomorrow, then send me another one :)

    I currently have a lot of emails on my inbox. If I haven't got back to you by tomorrow, then send me another one :)

  • mark 1 year ago
    NOTE: My email is [email protected]

    NOTE: My email is [email protected]

  • cbmagent-agent 1 year ago
    Sent it again Mark!

    Sent it again Mark!

Please login or signup to leave a response.

Login

or Sign Up

Sign Up

or Login
×
tnylea
Cheers Friend!

I'm Tony, the creator of this site. I'm trying to increase my twitter following. Want to follow me?

Follow @tnylea If not, no worries :)