Nikki

Nikki

Member Since 1 Year Ago

Experience Points 3,320
Experience Level 1

1,680 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 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

23 May
3 weeks ago

Nikki left a reply on Adding A Zero To A Calculation

Nevermind I just found it now after I had submitted this question.

This is what I did

@if(!empty($parent->price))
    @php
        $percent_price = $parent->price * 0.15;
        $total = $percent_price + $parent->price;
        $price = sprintf("%0.2f", $total);
    @endphp

    <td>
        R{{ $price }}
    </td>
@endif

Nikki started a new conversation Adding A Zero To A Calculation

This might be a simple and silly question, but I can't seem to get my head around it.

What I would like is that if my calculations needs a 0 at the end then it should put one.

For example I get 20.2 but what I want is 20.20

This is my code

@if(!empty($parent->price))
    @php
        $percent_price = $parent->price * 0.15;
        $price = $percent_price + $parent->price;
    @endphp

    <td>
        R{{ $price }}
    </td>
@endif
13 May
1 month ago

Nikki left a reply on Removing ID From Tab

@SNAPEY - Thanks Snapey, because of what you said I managed to get the browser tab to only show the invoice number and I managed to not let another person access someone else's invoice

Nikki left a reply on Removing ID From Tab

@BOBBYBOUWMANN - When I click on a link a pdf shows up in a new tab and on that tab I have both the invoice number and ID of that invoice so the tab would look like this INV0012 - 13 but what I would like is just the invoice number like this INV0012.

<title>{{ $order->invoice_number }}</title>

Is what gives me the invoice number on my browser tab.

I can't find anything on removing the ID that was automatically added to the browser tab.

Does that help?

Nikki started a new conversation Removing ID From Tab

I've created a pdf using barryvdh/laravel-dompdf the problem I'm having is that my web browser tab has the ID of the record and I would like to have it removed.

Here is my PDF

<html style="margin: 0; padding: 0;">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>{{ $order->invoice_number }}</title>

        <style>
            @font-face{
                font-family: 'arial';
                src: url('http://shop.test/fonts/arial.ttf') format('truetype');
            }

            @font-face{
                font-family: 'arial_bold';
                src: url('http://shop.test/fonts/arialbd.ttf') format('truetype');
            }

            tbody tr:nth-child(odd){
              background-color: #f3f4f5;
            }

            table{
                border: none;
            }
        </style>
    </head>

    <body style="margin: 0; padding: 0; font-family: arial; font-size: 13px;">
        <div style="background-color: #f3f4f5; width: 100%; height: 300px;">
            <div style="width: 700px; margin: 0 auto;">
                <div style="font-size: 50px; margin-bottom: 25px">
                    Invoice
                </div>
                            
                <div style="float: left; padding-left: 100px;">
                    <div style="font-family: arial_bold;">
                        BILL TO:
                    </div>

                    <div>
                        {{ $user->name }}
                    </div>

                    <div>
                        @if(!empty($user->company_name))
                            {{ $user->company_name }}
                        @endif
                    </div>
    
                    <br>

                    <div>
                        <div>{{ $address->complex }},</div>
                        <div>{{ $address->address }},</div>
                        <div>{{ $address->suburb }},</div>
                        <div>{{ $address->city }},</div>
                        <div>{{ $address->province }},</div>
                        <div>{{ $address->postal_code }}</div>
                    </div>
                </div>
            </div>

            <div style="float: right; margin-right: 80px;">
                <div>
                    <div>
                        <span style="font-family: arial_bold;">INVOICE NUMBER:</span> {{ $order->invoice_number }}
                    </div>

                    <div>
                        <span style="font-family: arial_bold;">ORDER DATE:</span> {{ Carbon\Carbon::parse($order->order_date)->format('d F Y') }}
                    </div>
                </div>
            </div>

            <div style="clear: both;"></div>
        </div>

        <div style="width: 700px; margin: 30px auto;">
            <table width="100%" cellspacing="0" cellpadding="0">
                <thead>
                    <tr>
                        <td></td>
                        <td style="font-family: arial_bold;">
                            Description
                        </td>
                        <td style="font-family: arial_bold; text-align: center;">
                            Qty
                        </td>
                        <td style="font-family: arial_bold; text-align: center;">
                            Unit Price
                        </td>
                        <td style="font-family: arial_bold; text-align: center;">
                            Total Price
                        </td>
                    </tr>
                </thead>

                <tbody>
                    @foreach($order_item->items as $item)
                        <?php
                            $image = getImagesArray($item['item']['image']);
                        ?>
                        <tr>
                            <td>
                                @if(!empty($image))
                                    <img src={!! asset("product_images/thumbs/$image[0]") !!}>
                                @endif
                            </td>
                            <td>    
                                {{ $item['item']['title'] }}
                            </td>
                            <td style="text-align: center;">
                                {{ $item['qty'] }}
                            </td>
                            <td style="text-align: center;">
                                R {{ $item['item']['price'] }}
                            </td>
                            <td style="text-align: center;">
                                R {{ $item['price'] }}
                            </td>
                        </tr>
                    @endforeach

                        <tr>
                            <td style="padding: 50px 0 5px 0; background-color: #fff;"></td>
                            <td style="padding: 50px 0 5px 0; background-color: #fff;"></td>
                            <td style="padding: 50px 0 5px 0; background-color: #fff;"></td>
                            <td style="padding: 50px 0 5px 0; background-color: #fff;"></td>
                            <td style="padding: 50px 0 5px 0; background-color: #fff;"></td>
                        </tr>

                        <tr>
                            <td rowspan="4" colspan="3" style="padding: 50px 0 5px 0; background-color: #fff; border-top: 2px solid #000;"></td>
                            <td style="text-align: right; padding: 50px 10px 5px 0; border-top: 2px solid #000;">
                                SUBTOTAL:
                            </td>
                            <td style="text-align: center; padding: 50px 0 5px 0; border-top: 2px solid #000;">
                                R {{ $order_item->totalPrice }}
                            </td>
                        </tr>

                        @if(!empty($order->delivery_fee))
                            <tr>
                                <td style="text-align: right; padding: 0 10px 15px 0;">
                                    DELIVERY FEE:
                                </td>
                                <td style="text-align: center; padding: 0 0 15px 0;">
                                    R {{ $order->delivery_fee }}
                                </td>
                            </tr>
                        @endif

                        <tr>
                            <td style="text-align: right; padding: 0 10px 0 0; background-color: #000000; color: #ffffff; font-family: arial_bold">
                                TOTAL:
                            </td>
                            <td style="border-left: 1px solid #000;  text-align: center; padding: 0; background-color: #000000; color: #ffffff; font-family: arial_bold">
                                R {{ $order->order_price }}
                            </td>
                        </tr>
                </tbody>
            </table>
        </div>
    </body>
</html>

and here is my controller function

public function invoicesPdf($id)
    {
        $order = Order::find($id);

        $user = Auth::user();
        $order_item = unserialize($order->cart);
        $address = json_decode($order->address);

        PDF::setOptions(['defaultFont' => 'sans-serif']);
        $pdf = PDF::loadView('public.pdf.invoice', compact('order', 'user', 'order_item', 'address'));

        return $pdf->stream();
    }
09 May
1 month ago

Nikki left a reply on Failed To Authenticate On SMTP Server With Username

@SNAPEY - Thank you so much. That worked I did have a # in my password

07 May
1 month ago

Nikki started a new conversation Failed To Authenticate On SMTP Server With Username

I'm getting this error when I hit submit on my contact form

Failed to authenticate on SMTP server with username "[email protected]" using 2 possible authenticators. 
Authenticator LOGIN returned Expected response code 235 but got code "535", with message "535 Incorrect authentication data ". 
Authenticator PLAIN returned Expected response code 235 but got code "535", with message "535 Incorrect authentication data ".

As far as I know all my details is corrected and my cpanel php is 7.3.

On my live site the contact form works correctly, but on my localhost I'm getting the above mentioned error. I used mailtrap to test out my contact form and that worked as well.

I can't understand why I'm getting this error when those details is working fine on my live site.

this is my .env

MAIL_DRIVER=smtp
MAIL_HOST=mail.domain.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=password
MAIL_ENCRYPTION=null
16 Apr
2 months ago

Nikki started a new conversation Returning A View Instead Of A Route

I've created a form using vue. The problem I'm having is that after the form is submitted it needs to go to another page and the problem is that I need to have it return a view() instead of a redirect.

So for example if I submit in vue then in my controller function I would have this

return ['redirect' => route('product.shoppingCart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice, 'menus_child' => $menus_child, 'contacts' => $contacts, 'supplier_code' => $supplier_code])];

and that would work, except for that all the items I need to pass through doesn't work.

but if I submited the form using this

return view('public.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice, 'menus_child' => $menus_child, 'contacts' => $contacts, 'supplier_code' => $supplier_code])->render();

I just get sent to the product page, but with a blank page.

Nikki started a new conversation Items In Cart Not Showing Up

I'm not sure if this is a laravel or vue question, but I'm trying to create an eCommerce site using both laravel and vue. I've been doing good for the most part. I've now run into a problem that I can't seem to understand. When I click on the "Add To Cart" button after selecting the code that I want it goes to my cart page, which is correct. The problem comes in is when I go to another product and I select the code and click "Add To Cart", it goes to the cart page but then the previous product that I had selected isn't there anymore, but my cart amount is correct and my total is correct, as if I had both products showing.

Here is my single_product.blade.php (this page shows the product that I would like to add to the cart)

@extends('layouts.public')
@section('content')
    <div class="content_wrapper">
        @foreach($single_product as $product)
            <div class="row single_product_wrapper">
                <div class="col-lg-4 col-md-12 col-sm-12">
                    <?php
                        $product_image = getImagesArray($product->image);
                        $product_image2 = getImagesArray($product->image2);
                    ?>
                    
                    <div class="white-block">
                        <img src="{{ asset('img/white-block.jpg') }}">
                    </div>

                    <div class="slider-for main_product_slider">
                        @if(!empty($product_image))
                            @foreach($product_image as $image)
                                <div>
                                    <img src="{{ asset('product_images/products/'.$image) }}" alt="{{ $image }}">
                                </div>
                            @endforeach
                        @endif
                    </div>

                    <div class="slider-nav main_product_nav">
                        @if(!empty($product_image2))
                            @foreach($product_image2 as $image2)
                                <div>
                                    <img src="{{ asset('product_images/thumbs/'.$image2) }}" alt="{{ $image2 }}">
                                </div>
                            @endforeach
                        @endif
                    </div>
                </div>

                <div class="col-lg-8 col-md-12-col-sm-12">
                    <h1>
                        {{ $product->title }}
                    </h1>

                    @foreach($parent_product as $parent)
                        <h1>
                            {{ $parent->title }}
                        </h1>
                        
                        <table style="width: 100%; height: 95px;" border="2" cellspacing="5" cellpadding="5">
                            <tbody>
                                <tr style="text-align: center;">
                                    <td>
                                        <strong>Code</strong>
                                    </td>
                                    
                                    @if(!empty($parent->description))
                                        <td>
                                            <strong>Description</strong>
                                        </td>
                                    @endif

                                    @if(!empty($parent->price))
                                        <td>
                                            <strong>Price</strong>
                                        </td>
                                    @endif
                                </tr>

                                <tr style="text-align: center;">
                                    @if(!empty($parent->code))
                                        <td>
                                            {{ $parent->code }}
                                        </td>
                                    @endif

                                    @if(!empty($parent->description))
                                        <td>
                                            {{ $parent->description }}
                                        </td>
                                    @endif

                                    @if(!empty($parent->price))
                                        <td>
                                            R {{ $parent->price }}
                                        </td>
                                    @endif
                                </tr>
                                
                                @if(count($parent->parent))
                                    @foreach($parent->parent as $child)
                                        <tr style="text-align: center;">
                                            @if(!empty($child->code))
                                                <td>
                                                    {{ $child->code }}
                                                </td>
                                            @endif

                                            @if(!empty($child->description))
                                                <td>
                                                    {{ $child->description }}
                                                </td>
                                            @endif

                                            @if(!empty($child->price))
                                                <td>
                                                    R {{ $child->price }}
                                                </td>
                                            @endif
                                        </tr>
                                    @endforeach
                                @endif
                            </tbody>
                        </table>
                    @endforeach

                    <!-- BEGIN ADD TO CART FORM -->
                    <div id="app">
                        @foreach($parent_product as $parent)
                            <code-selection :products="{{ $parent_product }}" :children="{{ $parent->parent }}"></code-selection>
                        @endforeach
                    </div>
                    <!-- END ADD TO CART FORM -->
                </div>
            </div>

        @endforeach
    </div>
@stop

And this is my CodeSelection.vue (This is where I bring in the select dropdown box so that I can grab the id of the selected code)

<template>
    <div>
        <form @submit.prevent="submit">
            <div class="row">
                <div class="col-lg-12">
                    <select name="code" id="code" class="form-control mx-sm-3 mb-2" v-model="selected_parent">
                        <option>Please select your code</option>
                        <option v-for="product in products" :value="product.id">
                            {{ product.code }}
                        </option>

                        <option v-for="child in children" :value="child.id">
                            {{ child.code }}
                        </option>
                    </select>
                </div>
            </div>

            <input type="submit" class="btn btn-dark btn-lg btn-block" value="Add To Cart">
        </form>
    </div>
</template>

<script>
    import axios from 'axios'

    export default {
        props: [
            'products',
            'children',
            'selected_parent'
        ],

        mounted() {
            console.log('Component mounted.')
        },

        methods: {
            submit(){
                var formData = new FormData();

                console.log('this is the select box - '+this.selected_parent);
                formData.append('code', this.selected_parent);

                return axios.post('/add-to-cart/'+this.selected_parent, formData)
                            .then(
                                function(response)
                                {
                                     console.log(response.data.redirect);
                                     window.location = response.data.redirect;
                                }
                            );
            },
        },
    }
</script>

and this is my controller function (This is where I put the products into a session and that passing it through to the cart page)

public function getAddToCart(Request $request, $id)
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

    $product = Product::find($id);

    $code = $request->code;

    $oldCart = Session::has('cart') ? Session::get('cart') : null;

    $cart = new Cart($oldCart);
    $cart->add($product, $product->id, $code);

    $request->session()->put('cart', $cart);

    return ['redirect' => route('product.shoppingCart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice, 'menus_child' => $menus_child, 'contacts' => $contacts, 'code' => $code])];
}

and this is my cart page

@extends('layouts.public')
@section('content')
    <div class="content_wrapper">
        @if(Session::has('cart'))
            <div class="container">
                <div class="cart_table">
                    <div class="table">
                        <div class="thead">
                            <div class="tr">
                                <div class="th border-bottom">Image</div>
                                <div class="th border-bottom">Code</div>
                                <div class="th border-bottom">&nbsp</div>
                                <div class="th border-bottom">Qty</div>
                                <div class="th border-bottom">Unit Price</div>
                                <div class="th border-bottom">Total Price</div>
                                <div class="th border-bottom">Remove</div>
                                <div class="th border-bottom"></div>
                            </div>
                        </div>

                        <div class="tbody">
                            @foreach($products as $product)
                                <?php
                                    $image = getImagesArray($product['item']['image']);
                                ?>

                                <div class="tr">
                                    <div class="td border-bottom" data-title="Image">
                                        @if(!empty($image))
                                            <img src={!! asset("product_images/thumbs/$image[0]") !!}>
                                        @endif
                                    </div>

                                    <div class="td border-bottom" data-title="Image">
                                        {{ $product['code'] }}
                                    </div>

                                    <div class="td border-bottom" data-title="Title">
                                        <strong>{{ $product['item']['title'] }}</strong>
                                    </div>

                                    <div class="td border-bottom" data-title="Qty">
                                        <div class="quantity_box">
                                            <div class="qty_number">
                                                <form action="{{ route('cart.update', ['id' => $product['item']['id']]) }}" method="POST">
                                                    {{ csrf_field() }}
                                                    <input type="text" value="{{ $product['qty'] }}">
                                                </form>

                                                <div class="inc button">
                                                    <a href="{{ route('product.addItem', ['id' => $product['code']]) }}" class="">
                                                        +
                                                    </a>
                                                </div>

                                                <div class="dec button">
                                                    <a href="{{ route('product.removeFromCart', ['id' => $product['item']['id']]) }}" class="">
                                                        -
                                                    </a>
                                                </div>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="td border-bottom" data-title="Unit Price">
                                        <span class="label label-success">R {{ $product['item']['price'] }}</span>
                                    </div>

                                    <div class="td border-bottom" data-title="Total Price">
                                        <span class="label label-success">R {{ $product['price'] }}</span>
                                    </div>

                                    <div class="td border-bottom remove-item" data-title="Remove">
                                        <a href="{{ route('product.removeWholeItem', ['id' => $product['item']['id']]) }}" class="">
                                            <i class="fa fa-times"></i>
                                        </a>
                                    </div>
                                </div>
                            @endforeach
                        </div>
                    </div>
                </div>

                <div class="cart_subtotal text-right">
                    <div class="subtotal_text">
                        Subtotal
                    </div>

                    <div class="subtotal_price text-right">
                        R {{ $totalPrice }}
                    </div>
                </div>

                <div class="cart_btns text-right">
                    <a href="{{ url('products.html') }}" class="btn btn-outline-primary">Continue Shopping</a>

                    @if(Auth::check())
                        <a href="{{ route('cart.deliveryConfirmation') }}" class="btn btn-outline-success">Proceed to Checkout</a>
                    @else
                        <a href="{{ route('account.loginRegister') }}" class="btn btn-outline-success">Proceed to Checkout</a>
                    @endif
                </div>
            </div>
        @else
            <div class="row">
                <div class="col-sm-6 col-md-6 col-md-offset-3 col-sm-offset-3">
                    <h2>No items in cart!</h2>
                </div>
            </div>
        @endif
    </div>
@stop

and this is my routes.php

Route::get('/shopping-cart', '[email protected]')->name('product.shoppingCart');
Route::any('/add-to-cart/{id}', '[email protected]')->name('product.addToCart');

This is my Cart.php

<?php

namespace App;

use Session;

class Cart
{
    public $items = null;
    public $totalQty = 0;
    public $totalPrice = 0;

    public function __construct($oldCart)
    {
        if($oldCart)
        {
            $this->items = $oldCart->items;
            $this->totalQty = $oldCart->totalQty;
            $this->totalPrice = $oldCart->totalPrice;
        }
    }

    public function add($item, $id, $code)
    {
        $storedItem = ['qty' => 0, 'price' => $item->price, 'item' => $item, 'code' => $code];

        if($this->items)
        {
            if(array_key_exists($id, $this->items))
            {
                $storedItem = $this->items[$id];
            }
        }

        $storedItem['qty']++;
        $storedItem['price'] = $item->price * $storedItem['qty'];
        $this->items[$code] = $storedItem;
        $this->totalQty++;
        $this->totalPrice += $item->price;
    }

    public function sendToCart($item, $id)
    {
        $storedItem = ['qty' => 0, 'price' => $item->price, 'item' => $item];

        if($this->items)
        {
            if(array_key_exists($id, $this->items))
            {
                $storedItem = $this->items[$id];
            }
        }

        $storedItem['qty']++;
        $storedItem['price'] = $item->price * $storedItem['qty'];
        $this->items[$id] = $storedItem;
        $this->totalQty++;
        $this->totalPrice += $item->price;
    }

    public function reduceByOne($id)
    {
        $this->items[$id]['qty']--;
        $this->items[$id]['price'] -= $this->items[$id]['item']['price'];
        $this->totalQty--;
        $this->totalPrice -= $this->items[$id]['item']['price'];

        if($this->items[$id]['qty'] <= 0)
        {
            unset($this->items[$id]);
        }
    }

    public function removeWholeItem($id)
    {
        $this->totalQty -= $this->items[$id]['qty'];
        $this->totalPrice -= $this->items[$id]['price'];

        unset($this->items[$id]);
    }
}

Nikki left a reply on Getting A Vue Form To Go To The Next Page After Submit

@FTIERSCH - I needed to use it so that I could get an id from a select drop down

Nikki left a reply on Getting A Vue Form To Go To The Next Page After Submit

I found my issue. I forgot to change

return view('public.shopping-cart', compact('supplier_code'));

to

return ['redirect' => route('product.shoppingCart')];

in my laravel controller function

Nikki started a new conversation Getting A Vue Form To Go To The Next Page After Submit

I'm using both laravel and vue and I'm trying to get my vue form to go to another page when I've submitted, but the problem is that once it's submitted it refreshes and goes back to the page it's on instead of the other page.

When I check my network tab in the dev tools, it posted to the right page but it doesn't show up in the browser

This is my vue

<template>
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">Example Component</div>

                    <div class="card-body">
                        I'm an Supplier Code Selection component.
                        <br>

                        <form @submit.prevent="submit">
                            <label for="parent-product">Parent Product</label>
                            <select name="parent-product" id="parent-product" class="form-control" v-model="selected_parent">
                                <option>Please select your code</option>
                                <option v-for="product in products" :value="product.id">
                                    {{ product.supplier_code }}
                                </option>

                                    <option v-for="child in children" :value="child.id">
                                        {{ child.supplier_code }}
                                    </option>
                            </select>

                            <input type="submit" class="btn btn-primary" value="Submit">
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import axios from 'axios'

    export default {
        props: [
            'products',
            'children',
            'selected_parent'
        ],

        mounted() {
            console.log('Component mounted.')
        },

        methods: {
            submit(){
                var formData = new FormData();

                console.log('this is the select box - '+this.selected_parent);
                formData.append('parent-product', this.selected_parent);

                return axios.post('/add-to-cart/'+this.selected_parent, formData);
            },
        },
    }
</script>

My route

Route::any('/add-to-cart/{id}', '[email protected]')->name('product.addToCart');

My controller function

public function getAddToCart(Request $request, $id)
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

    $product = Product::find($id);

    $supplier_code = $request->supplier_code;

    $oldCart = Session::has('cart') ? Session::get('cart') : null;

    $cart = new Cart($oldCart);
    $cart->add($product, $product->id, $supplier_code);

    $request->session()->put('cart', $cart);

    return view('public.shopping-cart', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice, 'menus_child' => $menus_child, 'contacts' => $contacts, 'supplier_code' => $supplier_code]);
}
09 Apr
2 months ago

Nikki left a reply on Getting A Null When Accessing A Relation

@tykus - Thanks so much. I hadn't realized that was the problem. So I just changed the parent column in my table to parent_id

Nikki started a new conversation Getting A Null When Accessing A Relation

I'm not able to access the relation that I created. So in my database I have a product table and that table has a parent column and that parent column refrences the id of the product in the product table. When I dd($parent->parent) I get a null. I've been looking at this for a while and I can't see where I'm going wrong.

This is my controller code

public function productItem($slug)
{
    $parent_product = Product::where('slug', $slug)->with('parent')->get();

    return view('public.single_product', compact('parent_product'));
}

and this is what I have in my view

@foreach($parent_product as $parent)
    {{ $parent->title }}
    @php
        dd($parent->parent)
    @endphp
@endforeach

If I do this

@foreach($parent_product as $parent)
    {{ $parent->title }}
    
    @foreach($parent->parent as $child)
        {{ $child->title }}
    @endforeach
@endforeach

I get this error

Invalid argument supplied for foreach()
02 Apr
2 months ago

Nikki left a reply on Saving Sessions To The Database

So I managed to save my session, but my invoice_number session isn't there. When I unserialize the payload I don't see it there at all.

Here is my code

public function deliveryConfirmation()
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

     // CHECKS TO SEE IF THERE IS NO CART SESSION
    if(!Session::has('cart'))
    {
        return view('public.shopping-cart', compact('menus_child', 'contacts'));
    }

    // GETS THE CART THAT IS STORED IN THE SESSION
    $oldCart = Session::get('cart');
    $cart = new Cart($oldCart);

    $invoice_number = invoiceNumber();
    Session::put('invoice_number', $invoice_number);

    $data = DB::table('sessions')->get();

    $data_payload = $data[0]->payload;
    $payload_decode = base64_decode($data_payload);
    $payload = unserialize($payload_decode);

    dd($payload);

    return view('public.delivery-confirmation', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice, 'menus_child' => $menus_child, 'contacts' => $contacts, 'invoice_number' => $invoice_number]);
}

and this is what I get after dd($payload)

array:5 [▼
  "_token" => "ukNk2694LKPeFqi9dXUOBPoiBYU8JCH89MEvhdKr"
  "_previous" => array:1 [▼
    "url" => "http://laravel.test/shopping-cart"
  ]
  "_flash" => array:2 [▼
    "old" => []
    "new" => []
  ]
  "login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 3
  "cart" => Cart {#293 ▼
    +items: array:1 [▼
      24 => array:3 [▼
        "qty" => "1"
        "price" => 1.0
        "item" => Product {#278 ▼
          #fillable: array:8 [▶]
          #connection: "mysql"
          #table: "products"
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:11 [▶]
          #original: array:11 [▶]
          #changes: []
          #casts: []
          #dates: []
          #dateFormat: null
          #appends: []
          #dispatchesEvents: []
          #observables: []
          #relations: []
          #touches: []
          +timestamps: true
          #hidden: []
          #visible: []
          #guarded: array:1 [▶]
        }
      ]
    ]
    +totalQty: "1"
    +totalPrice: 1.0
  }
]

For me, it looks like the only thing being saved is my cart session

01 Apr
2 months ago

Nikki left a reply on Saving Sessions To The Database

I didn't see @devfrey answer until now. I will check it out

Nikki left a reply on Saving Sessions To The Database

@EDOC - I did that, but the table didn't save my invoice number

Nikki left a reply on Saving Sessions To The Database

If I wanted to save something else in the sessions table like an invoice_number. Where would I go to do that?

Nikki started a new conversation Saving Sessions To The Database

This might be a silly question, but I haven't found any answers.

I would like to know if I need to create a model Session if I want to save sessions to the database?

29 Mar
2 months ago

Nikki left a reply on Getting A Forbidden When Trying To Access My Controller

@siangboon - I removed the public folder

@jlrdw - I'm not posting to the gateway at the moment. I'm trying to grab the values in my form first

@snapey - All my links and forms work except for this one and that is why I'm so confused

28 Mar
2 months ago

Nikki left a reply on Getting A Forbidden When Trying To Access My Controller

@JLRDW - This is supposed to go straight to the controller method. Don't worry I'm not storing any of the peoples information especially their cc numbers and things like that. I wouldn't feel comfortable doing that @Cronix - They not all my routes I only posted those ones, but if you like I can post all of them. So client_area is just a folder that I've installed the shop app to and there is no other payment.gateway routes, that was the first thing I checked @siangboon - So client_area is a folder I got on my server and the shop is the laravel app that I installed into client_area. There is no payment-gateway folder

Nikki left a reply on Getting A Forbidden When Trying To Access My Controller

@JLRDW - This is supposed to go straight to the controller method. Don't worry I'm not storing any of the peoples information especially their cc numbers and things like that. I wouldn't feel comfortable doing that

27 Mar
2 months ago

Nikki started a new conversation Getting A Forbidden When Trying To Access My Controller

I've created a form that when submitted it needs to go to a controller function.

At the moment when I'm submitting my form I keep getting


Forbidden

You don't have permission to access /client_area/shop/payment-gateway on this server.

Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.

I've done forms before but this is the first time this has happened to me and it has me stumped.

my form

<div class="payment-form">
    <form action="{{ route('payment.gateway') }}" method="POST">
        @csrf
        
        <input type="hidden" name="return_url" value="{{ route('payment.success') }}">
        <input type="hidden" name="cancel_url" value="{{ route('payment.cancel') }}"> 
        <input type="hidden" name="m_payment_id" value="{{ $invoice_number }}">
        <input type="hidden" name="amount" class="completePrice" value="">
        <input type="hidden" name="item_name" value="Test Item">
        <input type="hidden" name="item_description" value="A test product">

        <input type="hidden" name="delivery_collection" class="delivery_collection" value="">
        <input type="hidden" name="delivery_fee" class="delivery_fee" value="{{ $delivery }}">
        <input type="hidden" name="delivery_address" class="delivery_address" value="{{ $address }}">

        <button type="submit" class="btn btn-success float-right confirm-snapscan-order">
            Confirm Order
        </button>
    </form>
</div>

my routes

Route::group(['middleware' => ['web', 'auth']], function(){
    Route::get('/account/dashboard', '[email protected]')->name('account.dashboard');
    Route::get('/account/details', '[email protected]')->name('account.details');
    Route::get('/account/track-orders', '[email protected]')->name('account.track-orders');
    Route::get('/account/invoices', '[email protected]')->name('account.invoices');
    Route::get('/account/address', '[email protected]')->name('account.addresses.index');
    Route::get('/account/sort-orders', '[email protected]')->name('account.sort-orders');
    Route::get('/account/order-details/{invoice_number}', '[email protected]')->name('account.order-details');
    Route::get('/account/invoice-pdf/{id}', '[email protected]')->name('account.invoices.pdf');
    Route::get('/account/create-address', '[email protected]')->name('account.create.address');
    Route::get('/account/edit-address/{id}', '[email protected]')->name('account.edit.address');
    Route::get('/delivery-confirmation', '[email protected]')->name('cart.deliveryConfirmation');
    Route::get('/account/edit-delivery-address/{id}', '[email protected]')->name('account.edit.delivery.address');
    Route::get('/payment-success', '[email protected]')->name('payment.success');
    Route::get('/payment-cancel', '[email protected]')->name('payment.cancel');

    Route::post('/account/personal-details', '[email protected]')->name('post.personal-details');
    Route::post('/account/business-details', '[email protected]')->name('post.business-details');
    Route::post('/account/addresses-radio/{id}', '[email protected]')->name('account.post.addresses.radio');
    Route::post('/account/create-address', '[email protected]')->name('account.post.address');
    Route::post('/account/edit-address/{id}', '[email protected]')->name('account.update.address');
    Route::post('/payment-gateway', '[email protected]')->name('payment.gateway');

    Route::delete('/account/delete-delivery-address/{id}', '[email protected]')->name('account.delete.delivery.address');
});

I've only done a dd() to make sure I hit the right function

public function paymentGateway()
{
    dd('this is a payment gateway');
}
25 Mar
2 months ago

Nikki started a new conversation Getting Info From A Json_decode String

I made a cart that when it's saved it is saved as a json_encode string. Everything looks great and kind of works. So what happens is that the cart is in a session then I save it to the database like this $order->cart = json_encode($cart). It saves nicely. The problem I have is that I can't access the product's title.

I can access for example the totalQty or the totalPrice by doing this {{ $cart->totalPrice }}, but not able to access anything else.

Here is the cart that is in my database

{"items":
    {"25":
        {"qty":"1",
        "price":259.58,
        "item":{
            "id":25,
            "title":"Product 2",
            "order":2,
            "supplier_code":"product-2",
            "description":"This is product 2",
            "price":"259.58",
            "image":"[\"product-2.jpg\"]",
            "image2":"[\"product-2.jpg\"]",
            "slug":""product-2",
            "created_at":"2018-08-23 12:19:44",
            "updated_at":"2019-02-11 09:17:14"}},

        "27":{
            "qty":"2",
            "price":6,
            "item":{
                "id":27,
                "title": "Product 3",
                "order":3,
                "supplier_code":""product-3",
                "description":"This is product 3",
                "price":"3.00",
                "image":"[\"product-3.jpg\"]",
                "image2":"[\"product-3.jpg\"]",
                "slug":"product-3",
                "created_at":"2018-08-23 12:22:18",
                "updated_at":"2019-02-11 09:17:38"
            }
        }
    },

    "totalQty":"2",
    "totalPrice":265.58
}

and this is how I'm decoding it

public function getInvoice($invoice_number)
{
    $orders = Order::where('invoice_number', $invoice_number)->get();

    foreach($orders as $order)
    {
        if($order->cart)
        {
            $cart = json_decode($order->cart);
        }else{
            $cart = [];
        }
    }

    return view('public.snapscan', compact('cart'));
}
20 Mar
2 months ago

Nikki started a new conversation Trying To Get Property Of A Non-object In A Middleware

I'm trying to create a middleware that will only allow users that have the user_type customer, but the error I'm getting is

Trying to get property 'user_type' of non-object

I'm not sure why i'm getting this, because I'm assuming that if I go directly to the url that is protected then it should go straight to the home page

here is my middleware

<?php

namespace App\Http\Middleware;

use Closure;
use Auth;

class Customer
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if(Auth::user()->user_type == 'customer'){
            return $next($request);
        }

        return redirect('/')->with('error', 'You have not customer access');
    }
}

and this is my routes

Route::group(['middleware' => 'customer'], function(){
    Route::get('/account/dashboard', '[email protected]')->name('account.dashboard');
    Route::get('/account/details', '[email protected]')->name('account.details');
});

and I have this in my $routeMiddleware

'customer' => \App\Http\Middleware\Customer::class,
19 Mar
2 months ago

Nikki left a reply on Can't Unserialize My Address

@CLICK - I used json instead of the serialize and that worked much better. I don't know why I didn't think of that before. Thank you so much for helping

Nikki left a reply on Can't Unserialize My Address

@SNAPEY - I'm still getting the same error

Nikki left a reply on Can't Unserialize My Address

@CLICK - This is what I get

O:11:"App\Address":26:{s:11:"�*�fillable";a:7:{i:0;s:7:"user_id";i:1;s:7:"address";i:2;s:7:"complex";i:3;s:6:"suburb";i:4;s:4:"city";i:5;s:8:"province";i:6;s:11:"postal_code";}s:13:"�*�connection";s:5:"mysql";s:8:"�*�table";s:9:"addresses";s:13:"�*�primaryKey";s:2:"id";s:10:"�*�keyType";s:3:"int";s:12:"incrementing";b:1;s:7:"�*�with";a:0:{}s:12:"�*�withCount";a:0:{}s:10:"�*�perPage";i:15;s:6:"exists";b:1;s:18:"wasRecentlyCreated";b:0;s:13:"�*�attributes";a:11:{s:2:"id";i:4;s:7:"user_id";i:3;s:8:"selected";i:1;s:7:"complex";s:17:"Unit 39, La Monte";s:7:"address";s:22:"28 Parklands Main Road";s:6:"suburb";s:9:"Parklands";s:4:"city";s:9:"Cape Town";s:8:"province";s:12:"Western Cape";s:11:"postal_code";s:4:"7441";s:10:"created_at";s:19:"2019-03-13 06:37:12";s:10:"updated_at";s:19:"2019-03-14 09:47:05";}s:11:"�*�original";a:11:{s:2:"id";i:4;s:7:"user_id";i:3;s:8:"selected";i:1;s:7:"complex";s:17:"Unit 39, La Monte";s:7:"address";s:22:"28 Parklands Main Road";s:6:"suburb";s:9:"Parklands";s:4:"city";s:9:"Cape Town";s:8:"province";s:12:"Western Cape";s:11:"postal_code";s:4:"7441";s:10:"created_at";s:19:"2019-03-13 06:37:12";s:10:"updated_at";s:19:"2019-03-14 09:47:05";}s:10:"�*�changes";a:0:{}s:8:"�*�casts";a:0:{}s:8:"�*�dates";a:0:{}s:13:"�*�dateFormat";N;s:10:"�*�appends";a:0:{}s:19:"�*�dispatchesEvents";a:0:{}s:14:"�*�observables";a:0:{}s:12:"�*�relations";a:0:{}s:10:"�*�touches";a:0:{}s:10:"timestamps";b:1;s:9:"�*�hidden";a:0:{}s:10:"�*�visible";a:0:{}s:10:"�*�guarded";a:1:{i:0;s:1:"*";}}

Nikki started a new conversation Can't Unserialize My Address

I serialized my address so that I could have it saved to a table in one go, but now when I try to unserialize it I get this error

unserialize(): Error at offset 40 of 1597 bytes

I'm not sure if I'm doing anything wrong

Here is my code

public function orderDetails($invoice_number)
    {
        $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
        $contacts = Contact::all();

        $orders = Order::where('invoice_number', $invoice_number)->get();

        $user_id = Auth::user()->id;

        foreach($orders as $order)
        {
            $order_address = $order->address;

            $address = unserialize($order_address);
        }

        dd($address);
        return view('public.users.order-details', compact('menus_child', 'contacts', 'orders', 'addresses'));
    }
14 Mar
3 months ago

Nikki left a reply on Not Sure How To Get 3 Months

@GORAKHYADAV - I'm still getting nothing

Nikki left a reply on Not Sure How To Get 3 Months

I'm getting nothing when I dd($three_months);

Nikki started a new conversation Not Sure How To Get 3 Months

I'm trying to create a sort function where if it's selected it will display the necessary amount of orders. For example if the user selects to display orders from the lat 3 months then that needs to be displayed.

At the moment I'm stuck at the section where I say it's 3 monts

public function trackOrders()
    {
        $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
        $contacts = Contact::all();

        $orders = Auth::user()->orders->sortByDesc('order_date');
        $orders->transform(function($order, $key){
                    $order->cart = unserialize($order->cart);
                    return $order;
                });

        $from = Carbon\Carbon::now('+2:00');

    // This is where I'm stuck
        $to = 

        $three_months = Order:: where($from, '>', $to);

        return view('public.users.track-orders', compact('menus_child', 'contacts', 'orders', 'order_item'));
    }

Nikki left a reply on Saving 2 Radio Buttons

So I've managed to do it. I'm not sure if there is a better way but this works.

In my function I did

public function postAddressesRadio(Request $request, $id)
{
    $address = Address::findOrFail($id);
    $user_id = Auth::user()->id;

    $addresses = Address::where('user_id', $user_id)->get();

    foreach($addresses as $address)
    {
        if($address->id == $id)
        {
            $address->selected = "1";
        }else{
            $address->selected = "0";
        }

        $address->save();
    }

Nikki started a new conversation Saving 2 Radio Buttons

In my page I can have multiple addresses, but the user can only select one address. The problem I'm having is that both my radio buttons are being saved instead of just one. So if the user has 2 addresses then only one should have selected = 1 and the other address should be selected = 0, but at the moment both address = 1

My form

@foreach($addresses as $address)
    <div class="col-lg-4">
        <form id="address-radio" action="{{ route('account.post.addresses.radio', $address->id) }}" method="post">
            @csrf
            <div class="form-check">
                <input type="radio" class="form-check-input" name="address_option" id="address_{{ $address->id }}" {!! $address->selected == '1' ? 'checked' : '' !!}>
                <label for="address_{{ $address->id }}" class="form-check->label">
                    @if(!empty($address->complex))
                        {{ $address->complex }} <br>
                    @endif
                    {{ $address->address }} <br>
                    {{ $address->suburb }} <br>
                    {{ $address->city }} <br>
                    {{ $address->province }} <br>
                    {{ $address->postal_code }} <br>
                </label>
            </div>
        </form>
    </div>
@endforeach

and this is my function

public function postAddressesRadio(Request $request, $id)
{
    $selected = Address::findOrFail($id);

    if($request->address_option == 'on'){
        $selected->selected = '1';
    }else{
        $selected->selected = '0';
    }

    $selected->save();

    return redirect()->back()->with('success', 'Address was updated');
}
11 Mar
3 months ago

Nikki started a new conversation Method Illuminate\Database\Eloquent\Collection::orderBy Does Not Exist.

I've made a list and now I'm trying to use orderBy to sort the orders by order_date. The problem I'm getting is this error

Method Illuminate\Database\Eloquent\Collection::orderBy does not exist.

I can't see where I went wrong.

Here is my code

public function trackOrders()
    {
        $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
        $contacts = Contact::all();

        $orders = Auth::user()->orders;
        $order->transform(function($order, $key){
            $order->cart = unserialize($order->cart);
            return $order;
        })->orderBy('order_date', 'desc');

        return view('public.users.track-orders', compact('menus_child', 'contacts', 'orders', 'order_item'));
    }

I've also tried

$order_test = $orders->orderBy('order_date', 'desc')->get();

and I still got the same error

Nikki left a reply on Trying To Get Property 'items' Of Non-object

Nevermind. I think it's working now. For some reason my cart field had a null

Nikki started a new conversation Trying To Get Property 'items' Of Non-object

I'm trying to get a list of the items in my cart, I serialized the cart and added it to my database. The problem I have is that when I try to loop through my cart I get this error

Trying to get property 'items' of non-object

If I dd($order->cart->items); then at least 1 cart shows up, so I'm not getting why I'm recieving the error .

My function

public function trackOrders()
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

    $orders = Auth::user()->orders;
    $orders->transform(function($order, $key){
        $order->cart = unserialize($order->cart);
        return $order;
    });

    return view('public.users.track-orders', compact('menus_child', 'contacts', 'orders'));
}

My blade

@foreach($orders as $order)
    <div class="row">
        <div class="col-lg-12">
            <div class="card mt-15">
                <div class="card-header">
                    <div class="invoice-details">
                        <div>
                            {{ Carbon\Carbon::now() }}

                            ARM0001 | Ordered: {{ Carbon\Carbon::parse($order->order_date)->format('d F Y') }} | Paid: Add Paid date
                        </div>
                        <div>
                            Delivered: {{ Carbon\Carbon::parse($order->delivered_date)->format('d F Y') }}
                        </div>
                    </div>

                    <div class="invoice-buttons">
                        <a href="#" class="btn btn-primary">Track Order</a> | 
                        <a href="#" class="btn btn-primary">Order Details</a>
                    </div>
                </div>

                <div class="card-body">
                    <div class="row text-center">
                        @foreach($order->cart->items as $item)
                            {{ $item['item']['title'] }}
                        @endforeach
                    </div>
                </div>
            </div>
        </div>
    </div>
@endforeach

If there is anything else that I need to provide please let me know

04 Mar
3 months ago

Nikki left a reply on Some Advice For Saving An Invoice

@SCREENBEETLE - I am saving them at the same time at the moment. I now need to figure out how to add a new invoice number when I hit that duplicate error

Nikki left a reply on Some Advice For Saving An Invoice

@SCREENBEETLE - I'm creating the invoice number in my helper.php like this

function invoiceNumber()
    {
        $latest = App\Order::latest()->first();

        if (! $latest) {
            return 'ARM0001';
        }

        $string = preg_replace("/[^0-9\.]/", '', $latest->invoice_number);

        return 'ARM' . sprintf('%04d', $string+1);
    }

and then I call it in my controller like this

$invoice_number = invoiceNumber();

and then pass it through to the view

Nikki started a new conversation Some Advice For Saving An Invoice

I'm hoping to get some advice. I'm trying to create an online shop and the shop is going to have an invoice number. Now if I try to purchase an item at the same time I get the same invoice number. What I would like to know is do I make sure that doesn't happen or is something like that very unlikely?

01 Mar
3 months ago

Nikki started a new conversation Getting The Invoice Number To Go To Cancel Function

I'm hoping someone can help me and tell me if I'm going in the right direction or help me out. I'm creating an online shop and I'm using payfast as a payment gateway. Before I had a problem with getting my information saved upon success, but someone suggested that I rather post to a controller and then make that controller go to the url. I did that and it's working and saving when I click confirm. The problem now is that if someone clicks on cancel it still gets saved and I would like that if the user ends up cancelling and going to the cancel page then it deletes the order from the database. I can't see how I can delete the data when a user clicks cancel.

This is my code for both the payPayfast method where I save the data and my cancelPayfast where I would like to delete the data

public function payPayfast(Request $request)
{

    $oldCart = Session::get('cart');
    $cart = new Cart($oldCart);

    $order = new Order();
    $order->cart = serialize($cart);
    $order->delivered_date = null;
    $order->process = 'Order paid';
    $order->order_date = Carbon::now('+2:00');
    $order->paid = '1';
    $order->order_price = $request->amount;

    Auth::user()->orders()->save($order);

    $merchant_id = $request->merchant_id;
    $merchant_key = $request->merchant_key;
    $return_url = $request->return_url;
    $cancel_url = $request->cancel_url;
    $m_payment_id = $request->m_payment_id;
    $amount = $request->amount;
    $item_name = 'Test Item From Controller';
    $item_description = 'This is a test product';
    $email_confirmation = '1';
    $confirmation_address = '[email protected]';
    $payment_method = $request->payment_method;
    $signature = $request->signature;

    $url = 'https://sandbox.payfast.co.za/eng/process?merchant_id='.$merchant_id.'&merchant_key='.$merchant_key.'&return_url='.$return_url.'&cancel_url='.$cancel_url.'&m_payment_id='.$m_payment_id.'&amount='.$amount.'&item_name='.$item_name.'&item_description='.$item_description.'&email_confirmation='.$email_confirmation.'&confirmation_address='.$confirmation_address.'&payment_method='.$payment_method;

    return redirect()->to($url);
}

public function cancelPayfast()
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

    $oldCart = Session::get('cart');
    $cart = new Cart($oldCart);

    if(Session::has('cart')){
        Order::find()->delete(); //This is where I'm stuck
    }

    Category::find($id)->delete();

    return view('public.payfast.cancel', compact('menus_child', 'contacts'));
}

and this is my confirmation page. Sorry it's long but I thought it would be better to have all of it there

@extends('layouts.public')
@section('content')
    <div class="content_wrapper">
        <h1>Order Confrimation</h1>

        <?php
            $delivery = getDeliveryFee();
        ?>

        <div class="row">
            <div class="col-lg-12">
                <div class="accordion" id="accordionExample">
                    <div class="card">
                        <div class="card-header" id="headingOne">
                            <h2 class="mb-0">
                                <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
                                    Billing Information 
                                </button>
                            </h2>
                        </div>

                        <div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordionExample">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="address">
                                            <div>Unit 39 La Monte,</div>
                                            <div>28 Parklands Main Road,</div>
                                            <div>Parklands,</div>
                                            <div>Cape Town,</div>
                                            <div>Western Cape,</div>
                                            <div>7441</div>

                                            <div class="edit-delete">
                                                <a href="#">Edit</a> /
                                                <a href="#">Delete</a>
                                            </div>
                                        </div>
                                    </div>

                                    <div class="col-lg-6">
                                        <a href="#" class="btn btn-dark float-right mt-15">Add Address</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card">
                        <div class="card-header" id="headingTwo">
                            <h2 class="mb-0">
                                <button class="btn btn-link collapsed" id="delivery" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                                    Delivery/Collection
                                </button>
                            </h2>
                        </div>

                        <div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordionExample">
                            <div class="card-body">
                                <p>
                                    Please select your delivery option
                                </p>

                                <div class="delivery-option">
                                    <div class="form-check">
                                        <input type="radio" class="form-check-input" name="delivery-option" id="delivery" value="delivery">
                                        <label for="delivery" class="form-check-label">
                                            Delivery
                                        </label>
                                    </div>

                                    <div class="form-check">
                                        <input type="radio" class="form-check-input" name="delivery-option" id="collection" value="collection">
                                            <label for="collection" class="form-check-label">
                                                Collection
                                            </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card">
                        <div class="card-header" id="headingThree">
                            <h2 class="mb-0">
                                <button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
                                    Payment Options
                                </button>
                            </h2>
                        </div>

                        <div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordionExample">
                            <div class="card-body">
                                <div class="payment-option">
                                    <div class="form-check">
                                        <input type="radio" class="form-check-input" name="payment-option" id="payfast-eft" value="payfast-eft">
                                        <label for="payfast-eft" class="form-check-label">
                                            EFT with PayFast
                                        </label>
                                    </div>

                                    <div class="form-check">
                                        <input type="radio" class="form-check-input" name="payment-option" id="cod" value="cod">
                                        <label for="cod" class="form-check-label">
                                            Cash on Delivery
                                        </label>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="card">
                        <div class="card-header" id="headingThree">
                            <h2 class="mb-0">
                                <button class="btn btn-link collapsed" type="button" data-toggle="collapse" data-target="#collapseFour" aria-expanded="false" aria-controls="collapseThree">
                                    Review Your Order
                                </button>
                            </h2>
                        </div>

                        <div id="collapseFour" class="collapse" aria-labelledby="collapseFour" data-parent="#accordionExample">
                            <div class="card-body">
                                <table class="table table-bordered">
                                    <thead>
                                        <tr>
                                            <th scope="col">Product</th>
                                            <th scope="col">Code</th>
                                            <th scope="col">Quantity</th>
                                            <th scope="col">Unit Price</th>
                                            <th scope="col">Total</th>
                                        </tr>
                                    </thead>
                    
                                    <tbody>
                                        @foreach($products as $product)
                                            <tr>
                                                <th>{{ $product['item']['title'] }}</th>
                                                <td>{{ $product['item']['supplier_code'] }}</td>
                                                <td>{{ $product['qty'] }}</td>
                                                <td>R {{ $product['item']['price'] }}</td>
                                                <td>R {{ $product['price'] }}</td>
                                            </tr>
                                        @endforeach

                                        <tr>
                                            <th colspan="4">
                                                <div class="float-right">
                                                    Sub Total       
                                                </div>
                                            </th>
                                            <td id="totalPrice" data-price="{{ $totalPrice }}">R{{ $totalPrice }}</td>
                                        </tr>

                                        <tr class="delivery-fees">
                                            <th colspan="4">
                                                <div class="float-right">
                                                    Delivery Fee
                                                </div>
                                            </th>
                                            <td id="delivery-price" data-price="{{ $delivery }}">R{{ $delivery }}</td>
                                        </tr>

                                        <?php
                                            $total = $totalPrice + $delivery;
                                        ?>

                                        <tr class="total-price">
                                            <th colspan="4">
                                                <div class="float-right">
                                                    Total:      
                                                </div>
                                            </th>
                                            <td>R<span id="completePrice"></span></td>
                                        </tr>
                                    </tbody>

                                    <div class="confirm-order-btn pb-15">
                                        <div class="payfast-eft" style="display: none">

                                            <form action="{{ route('payfast.payPayfast') }}" method="POST">
                                                @csrf
                                                <input type="hidden" name="merchant_id" value="12345678">
                                                <input type="hidden" name="merchant_key" value="1234567891234">
                                                <input type="hidden" name="return_url" value="{{ route('payfast.success') }}">
                                                <input type="hidden" name="cancel_url" value="{{ route('payfast.cancel') }}"> <!-- PASS THE INVOICE NUMBER THRU CANCEL ROUTE -->
                                                <input type="hidden" name="m_payment_id" value="{{ $invoice_number }}">
                                                <input type="hidden" name="amount" class="completePrice" value="">
                                                <input type="hidden" name="item_name" value="Test Item">
                                                <input type="hidden" name="item_description" value="A test product">
                                                <input type="hidden" name="email_confirmation" value="1">
                                                <input type="hidden" name="confirmation_address" value="">
                                                <input type="hidden" name="payment_method" value="eft">

                                                <?php
                                                    $success = url('payfast-success');
                                                    $cancel = url('payfast-cancel');
                                                    $notify = url('payfast-notify');
                                                    $original_str = getAscii('merchant_id=12345678&merchant_key=1234567891234&return_url='.$success.'&cancel_url='.$cancel.'&notify_url='.$notify.'&m_payment_id=01AB&amount='.$totalPrice.'&item_name=Test Item&item_description=A test product&email_confirmation=1&[email protected]&payment_method=eft');
                                                    $hash_str = hash('MD5', $original_str);
                                                    $hash = strtolower($hash_str);
                                                ?>

                                                <input type="hidden" name="signature" value="{{ $hash }}">
                                                <div><input type="submit" value="submit" name="submit" /></div>
                                            </form>
                                        </div>

                                        <button class="btn btn-success float-right confirm-order">
                                            Confirm Order
                                        </button>
                                    </div>
                                </div>
                            </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
    $(document).ready(function(){

        var price = $("#totalPrice").data('price');

        $('#completePrice').html(price);
        $('.completePrice').val(price);

        $('input[type="radio"]').click(function(){
            if($(this).attr("value")=="collection"){
                $(".delivery-fees").hide('slow');

                var price = $("#totalPrice").data('price'); 
                var deliveryprice = 0; 
                var totalPrice = parseFloat(price) + parseFloat(deliveryprice);

                $('#completePrice').html(totalPrice);
                $('.completePrice').val(totalPrice);
            }

            if($(this).attr("value")=="delivery"){
                $(".delivery-fees").show('slow');

                var price = $("#totalPrice").data('price'); 
                var deliveryprice = $("#delivery-price").data('price'); 
                var totalPrice = parseFloat(price) + parseFloat(deliveryprice);

                $('#completePrice').html(totalPrice);
                $('.completePrice').val(totalPrice);

            }        
        });

        /* BEGIN EFT PAYFAST */
        $('input[type="radio"]').click(function(){
            if($(this).attr("value")=="payfast-eft"){
                $(".payfast-eft").show('slow');
                $(".payfast-card").hide();
                $(".i-pay").hide();
                $(".confirm-order").hide();
            }        
        });
        /* END EFT PAYFAST */
    });
    </script>   
@stop

I did try replacing

<input type="hidden" name="cancel_url" value="{{ route('payfast.cancel') }}">

with this

<input type="hidden" name="cancel_url" value="{{ route('payfast.cancel', [$invoice_number]) }}">

and having my web route look like this

Route::get('/payfast-cancel/{invoice_number}', '[email protected]')->name('payfast.cancel');

But I got this error

Missing required parameters for [Route: payfast.cancel] [URI: payfast-cancel/{invoice_number}].
28 Feb
3 months ago

Nikki left a reply on Getting An Invoice Number To Be Generated

@REALRANDYALLEN - Thank you so much. I've manged to get it to work with tweaking some stuff. Here's the final code

function invoiceNumber()
    {
        $latest = App\Order::latest()->first();

        if (! $latest) {
            return 'arm0001';
        }

        $string = preg_replace("/[^0-9\.]/", '', $latest->invoice_number);

        return 'arm' . sprintf('%04d', $string+1);
    }

I used thepreg_replace to separate the number so that I can increment it

Nikki left a reply on Getting An Invoice Number To Be Generated

@REALRANDYALLEN - Will the %04d always add four 0 regardless of the number?

For example will it be like this 0000150 or will it be like this 0150 and continue incrementing after the four integers are gone. For example 10521

Nikki left a reply on Getting An Invoice Number To Be Generated

I think I figured out the issue. My table wasn't empty. When I deleted everything it worked

Nikki left a reply on Getting An Invoice Number To Be Generated

@REALRANDYALLEN - I got a A non-numeric value encountered error

Nikki started a new conversation Getting An Invoice Number To Be Generated

I'm trying to generate an invoice number, but I'm getting null. I think I'm missing something but I'm not sure what it is.

Here is the invoiceNumber() code in my helpers.php

function invoiceNumber()
    {
        $orders = App\Order::all();

        if($orders->isEmpty())
        {
            $invoice = 'arm0001';
            return $invoice;
        }

        foreach($orders as $order)
        {
            $latest = App\Order::latest()->first();

            if($latest->order == true)
            {
                $invoice = 'arm'.$latest->order+1;
                return $invoice;
            }
        }
    }

and this is where I'm trying to get it to be taken

public function deliveryConfirmation()
{
    $menus_child = Menu::where('menu_id', 0)->with('menusP')->get();
    $contacts = Contact::all();

    if(!Session::has('cart'))
    {
        return view('public.shopping-cart', compact('menus_child', 'contacts'));
    }

    $oldCart = Session::get('cart');
    $cart = new Cart($oldCart);

    $invoice_number = invoiceNumber();
    dd($invoice_number);

    return view('public.delivery-confirmation', ['products' => $cart->items, 'totalPrice' => $cart->totalPrice, 'menus_child' => $menus_child, 'contacts' => $contacts, 'invoice_number' => $invoice_number]);
}
26 Feb
3 months ago

Nikki left a reply on Passing A Variable Through The Route Without Affecting The Url

So I changed and made a controller method, but it isn't passing my variables through to payfast

public function payPayfast(Request $request)
    {
        $data = [
            'merchant_id' => $request->merchant_id,
            'merchant_key' => $request->merchant_key,
            'return_url' => route('payfast.success'),
            'cancel_url' => route('payfast.cancel'),
            'm_payment_id' => $request->m_payment_id,
            'amount' => $request->amount,
            'item_name' => 'Test Item From Controller',
            'item_description' => 'This is a test product',
            'email_confirmation' => '1',
            'confirmation_address' => '[email protected]',
            'payment_method' => $request->payment_method,
            'signature' => $request->signature,
        ];

        return redirect()->to('https://sandbox.payfast.co.za/eng/process')->with('data', $data);
    }

Nikki left a reply on Passing A Variable Through The Route Without Affecting The Url

@MANELGAVALDA - I didn't think of that. Let me give it a try.