Nikki

Nikki

Member Since 1 Year Ago

Experience Points 3,520
Experience Level 1

1,480 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-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.

12 Jul
6 days ago

Nikki left a reply on Not Getting The Same Result In Vue

I will try and fix it, but I still don't get why I'm getting that error on my server and not on my localhost and at the moment that has me stumped

11 Jul
1 week ago

Nikki left a reply on Not Getting The Same Result In Vue

my localhost is php 7.2 and my server is php 7.1

Nikki started a new conversation Not Getting The Same Result In Vue

So I uploaded my site I was working on to my server and found out that the section that had the vue selection wasn't working. I don't know why that is happening when on my localhost it works just fine.

This is the error I get on my server site

Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed property based on the prop's value. Prop being mutated: "selected_parent"

but I don't get any errors on my localhost.

Was I supposed to have done something before I uploaded or after?

09 Jul
1 week ago

Nikki left a reply on Select Drop Down Not Selecting On First Click

I think I got it.

I changed

<select name="supplier_code" id="supplier_code" class="form-control mb-2 mt-10" v-model="selectedValue" required>

back to

<select name="supplier_code" id="supplier_code" class="form-control mb-2 mt-10" v-model="selected_parent" required>

and I did this

<option :value="selectedValue">Please select your code</option>

This seems to be working

Nikki left a reply on Select Drop Down Not Selecting On First Click

That didn't work either

Nikki left a reply on Select Drop Down Not Selecting On First Click

So this is what it looks like at the moment.

and this is what I would like it to look like

Nikki left a reply on Select Drop Down Not Selecting On First Click

I did do that but it's still the same as above

Nikki left a reply on Select Drop Down Not Selecting On First Click

I'm still not getting the Please select your code to be displayed and I'm not getting any errors.

Here is a link so that you can see what I mean.

Nikki left a reply on Select Drop Down Not Selecting On First Click

The select box disappeared and I got this error in my console.

TypeError: undefined has no properties

Nikki left a reply on Select Drop Down Not Selecting On First Click

If I remove that then I get a blank area instead of Please select your code

Nikki started a new conversation Select Drop Down Not Selecting On First Click

I created a page that uses a vue component and in that component is a drop down select. The issue I'm having is that I have to select the item twice before it gets selected. I'm not sure what I'm missing so that I can fix it.

Here is my vue component

<template>
    <div>
        <form @submit.prevent="submit">
            <div class="row">
                <div class="col-lg-12 supplier_code_select">
                    <select name="supplier_code" id="supplier_code" class="form-control mb-2 mt-10" v-model="selected_parent" required>
                        <option :value="selected_parent">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>
                </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('supplier_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>
23 May
1 month 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
2 months 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
2 months 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
2 months 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
3 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
3 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
3 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
3 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
3 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
3 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
3 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
3 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
3 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
3 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
4 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
4 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