Shiva

Shiva

Member Since 4 Years Ago

Experience Points 20,020
Experience Level 5

4,980 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.

20 May
2 days ago

Shiva left a reply on Issues With Sending An Email With A Pdf Attachment

@MVD - Then where is the issue? Because I get that error. It's what is confusing me so much

Shiva left a reply on Issues With Sending An Email With A Pdf Attachment

@MVD - I get

E:\Shiva\Wamp\www\shop\app\Http\Controllers\PublicController.php:497:string 'Test' (length=4)

Test is the name

Shiva left a reply on Issues With Sending An Email With A Pdf Attachment

@MVD - This is what I get

E:\Shiva\Wamp\www\shop\app\Http\Controllers\PublicController.php:497:
object(App\User)[422]
  protected 'fillable' => 
    array (size=16)
      0 => string 'user_type' (length=9)
      1 => string 'salutation' (length=10)
      2 => string 'name' (length=4)
      3 => string 'surname' (length=7)
      4 => string 'email' (length=5)
      5 => string 'password' (length=8)
      6 => string 'phone_number' (length=12)
      7 => string 'telephone_2' (length=11)
      8 => string 'trading_name' (length=12)
      9 => string 'company_name' (length=12)
      10 => string 'vat_number' (length=10)
      11 => string 'ck_number' (length=9)
      12 => string 'office_number' (length=13)
      13 => string 'work_email' (length=10)
      14 => string 'office_address' (length=14)
      15 => string 'contact_person' (length=14)
  protected 'hidden' => 
    array (size=2)
      0 => string 'password' (length=8)
      1 => string 'remember_token' (length=14)
  protected 'connection' => string 'mysql' (length=5)
  protected 'table' => string 'users' (length=5)
  protected 'primaryKey' => string 'id' (length=2)
  protected 'keyType' => string 'int' (length=3)
  public 'incrementing' => boolean true
  protected 'with' => 
    array (size=0)
      empty
  protected 'withCount' => 
    array (size=0)
      empty
  protected 'perPage' => int 15
  public 'exists' => boolean true
  public 'wasRecentlyCreated' => boolean false
  protected 'attributes' => 
    array (size=21)
      'id' => int 11
      'user_type' => string 'customer' (length=8)
      'salutation' => string 'Please select...' (length=16)
      'name' => string 'Test' (length=4)
      'surname' => string 'Testing' (length=7)
      'email' => string '[email protected]' (length=13)
      'email_verified_at' => null
      'password' => string 'y$JqgBrvkAjHspkDpf4HAn3.EHqxbg39RLXLltqk50N12/FqxrJ2bD6' (length=60)
      'phone_number' => null
      'telephone_2' => null
      'trading_name' => null
      'company_name' => null
      'vat_number' => null
      'ck_number' => null
      'office_number' => null
      'work_email' => null
      'office_address' => null
      'contact_person' => null
      'remember_token' => null
      'created_at' => string '2019-04-12 07:28:46' (length=19)
      'updated_at' => string '2019-04-24 05:26:09' (length=19)
  protected 'original' => 
    array (size=21)
      'id' => int 11
      'user_type' => string 'customer' (length=8)
      'salutation' => string 'Please select...' (length=16)
      'name' => string 'Test' (length=4)
      'surname' => string 'Testing' (length=7)
      'email' => string '[email protected]' (length=13)
      'email_verified_at' => null
      'password' => string 'y$JqgBrvkAjHspkDpf4HAn3.EHqxbg39RLXLltqk50N12/FqxrJ2bD6' (length=60)
      'phone_number' => null
      'telephone_2' => null
      'trading_name' => null
      'company_name' => null
      'vat_number' => null
      'ck_number' => null
      'office_number' => null
      'work_email' => null
      'office_address' => null
      'contact_person' => null
      'remember_token' => null
      'created_at' => string '2019-04-12 07:28:46' (length=19)
      'updated_at' => string '2019-04-24 05:26:09' (length=19)
  protected 'changes' => 
    array (size=0)
      empty
  protected 'casts' => 
    array (size=0)
      empty
  protected 'dates' => 
    array (size=0)
      empty
  protected 'dateFormat' => null
  protected 'appends' => 
    array (size=0)
      empty
  protected 'dispatchesEvents' => 
    array (size=0)
      empty
  protected 'observables' => 
    array (size=0)
      empty
  protected 'relations' => 
    array (size=0)
      empty
  protected 'touches' => 
    array (size=0)
      empty
  public 'timestamps' => boolean true
  protected 'visible' => 
    array (size=0)
      empty
  protected 'guarded' => 
    array (size=1)
      0 => string '*' (length=1)
  protected 'rememberTokenName' => string 'remember_token' (length=14)

Shiva left a reply on Issues With Sending An Email With A Pdf Attachment

@MVD - I still get the same error as before

Shiva left a reply on Issues With Sending An Email With A Pdf Attachment

@MUNAZZIL - if I do that then I get this error

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

Shiva left a reply on Issues With Sending An Email With A Pdf Attachment

@MANELGAVALDA - I've updated my question. Please let me know if it's ok

Shiva started a new conversation Issues With Sending An Email With A Pdf Attachment

I have a page that when the user successfully pays they get sent an email with an invoice.

The problems I'm having is that I keep getting this error

Trying to get property 'name' of non-object

It refers to this line

$user_name = $order->user->name;

I do know that this works because if I dd($user_name) I get the correct name.

The other problem I'm having is that, even though I get the above error I still get sent the invoice, but I don't get one invoice, I get multiple emails with the invoice attached.

This is my successPayment function

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

    if(Auth::check())
    {
        $orders = Order::all();
        $user_id = Auth::user()->id;

        foreach($orders as $order)
        {
            $exists = Order::find($order->id)->where('user_id', $user_id)->latest()->first();
            $exists->status = 'success';

            $exists->save();

            $invoice_number = Session::get('invoice_number');

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

            $user_name = $order->user->name;

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

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

            Mail::send('layouts.emails.invoice', [], function($message) use($pdf){
                $message->to('[email protected]', 'Testing PDF order')->subject('Someone has contacted you');
                $message->attachData($pdf->output(), 'invoice.pdf');
            });

        }
    }else{
        return redirect()->route('public.home');
    }

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

If I need to provide any other information please let me know

14 May
1 week ago

Shiva started a new conversation Getting Validation To Work For Address

I'm making a page that before the user submits they need to add their address.

For example: The user goes to the order confirmation and they forget to add their address and they fill in the rest of the page (the page has delivery/collection radio buttons and payment option radio buttons) when the user clicks on the confirm button the page needs to go back and give an error that the address wasn't entered.

The address portion of the page only has a "Add Address" button that takes the user to a form to enter their address.

Is there a way to do this. I thought maybe validation would work but I don't think I'm doing it correctly in this instance.

I have a hidden form that grabs some info and it has an address field in it so that it gets passed into the controller so that I can save it, but it's like it doesn't pick it up

My order-confirmation.blade.php

@extends('layouts.public')
@section('content')
    <div class="content_wrapper">
        <h1>Order Confirmation</h1>
        <?php
            $delivery = getDeliveryFee();
        ?>

        {{ $invoice_number }}
        <div class="row">
            <div class="col-lg-12">
                <div class="row">
                    <div class="col-lg-12 mt-15">
                        @if($message = Session::get('success'))
                            <div class="alert alert-success" role="alert">
                                {{ $message }}
                            
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                        @endif

                        @if($message = Session::get('error'))
                            <div class="alert alert-danger" role="alert">
                                {{ $message }}

                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>

        <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 {{ !$errors->any() ? 'show' : '' }}" aria-labelledby="headingOne" data-parent="#accordionExample">
                            <div class="card-body">
                                <div class="row">
                                    <div class="col-lg-6">
                                        <div class="address">
                                            @if ($errors->confirmation_errors->has('delivery_address'))
                                                <div class="help-block text-danger">
                                                    <strong>Please add an address NOW</strong>
                                                </div>
                                            @endif

                                            @foreach($addresses as $address)
                                                @if(!empty($address->complex))
                                                    {{ $address->complex }},
                                                @endif
                                                <div>{{ $address->address }},</div>
                                                <div>{{ $address->suburb }},</div>
                                                <div>{{ $address->city }},</div>
                                                <div>{{ $address->province }},</div>
                                                <div>{{ $address->postal_code }}</div>
                                                
                                                <div class="row edit-delete">
                                                    <div class="col-lg-2">
                                                        <a class="btn btn-primary edit-button" href="{{ route('account.edit.delivery.address', [$address->id]) }}">Edit</a> 
                                                        <span>/</span>
                                                    </div>

                                                    <div class="col-lg-2">
                                                        <form action="{{ route('account.delete.delivery.address', [$address->id]) }}" method="post">
                                                            @csrf
                                                            {{ method_field('DELETE') }}
                                                            <button class="btn btn-danger delete-button"><i class="fa fa-pencil"></i> Delete</button>
                                                        </form>
                                                    </div>
                                                </div>
                                            @endforeach
                                        </div>
                                    </div>

                                    <div class="col-lg-6">
                                        <a href="{{ route('account.add.address') }}" 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-collection" type="button" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
                                    Delivery/Collection
                                </button>
                            </h2>
                        </div>

                        <div id="collapseTwo" class="collapse {{ $errors->confirmation_errors->any() ? 'show' : '' }}" aria-labelledby="headingTwo" data-parent="#accordionExample">
                            <div class="card-body">
                                <p>
                                    Please select your delivery option
                                </p>

                                @if ($errors->confirmation_errors->has('delivery_collection'))
                                    <div class="help-block text-danger">
                                        <strong>Please select your delivery option</strong>
                                    </div>
                                @endif
        
                                <div class="delivery-option">
                                    <input type="radio" class="form-check-input {{ $errors->confirmation_errors->has('delivery_collection') ? 'is-invalid' : '' }}" name="delivery-option" id="delivery" value="delivery">
                                    <label for="delivery" class="form-check-label">
                                        Delivery
                                    </label>

                                    <input type="radio" class="form-check-input {{ $errors->confirmation_errors->has('delivery_collection') ? 'is-invalid' : '' }}" name="delivery-option" id="collection" value="collection">
                                    <label for="collection" class="form-check-label">
                                        Collection
                                    </label>
                                </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 {{ $errors->any() ? 'show' : '' }}" aria-labelledby="headingThree" data-parent="#accordionExample">
                            <div class="card-body">
                                @if ($errors->has('payment_option'))
                                    <div class="help-block text-danger">
                                        <strong>Please select a payment option</strong>
                                    </div>
                                @endif
                                
                                <div class="row">
                                    <div class="col-lg-12">
                                        <div class="payment-option">
                                            <input type="radio" class="form-check-input {{ $errors->has('payment_method') ? 'is-invalid' : '' }}" name="payment_method" id="payfast-eft" value="payfast-eft">
                                            <label for="payfast-eft" class="form-check-label">
                                                EFT with PayFast
                                            </label>
                                        </div>
                                    </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)
                                            <?php
                                                $image = getImagesArray($product['item']['image']);
                                            ?>
                                            <tr>
                                                <th>
                                                    @if(!empty($image))
                                                        <img src={!! asset("product_images/thumbs/$image[0]") !!}>
                                                    @endif

                                                    {{ $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>
                                </table>

                                <div class="confirm-order-btn pb-15">
                                    @foreach($products as $product)
                                        <!-- BEGIN PAYFAST EFT -->
                                        <div class="payfast-eft" style="display: none">
                                            <form action="{{ route('payment.gateway') }}" method="POST">
                                                @csrf
                                                <input type="hidden" name="merchant_id" value="merchant_id">
                                                <input type="hidden" name="merchant_key" value="merchant_key">
                                                <input type="hidden" name="return_url" value="{{ route('payfast.success') }}">
                                                <input type="hidden" name="cancel_url" value="{{ route('payfast.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="{{ $product['item']['title'] }}">
                                                <input type="hidden" name="item_description" value="{{ $product['item']['description'] }}">
                                                <input type="hidden" name="email_confirmation" value="1">
                                                <input type="hidden" name="confirmation_address" value="">
                                                <input type="hidden" name="payment_method" value="payfast_eft">
                                                <input type="hidden" name="delivery_collection" class="delivery_collection" value="">
                                                <input type="hidden" name="delivery_fee" class="delivery_fee" value="{{ $delivery }}">
                                                <!-- THIS IS WHERE THE ADDRESS IS ADDED TO THE HIDDEN FORM -->
                                                <input type="hidden" name="delivery_address" class="delivery_address" value="{{ $address }}">

                                                <?php
                                                    $success = url('payfast-success');
                                                    $cancel = url('payfast-cancel');
                                                    $notify = url('payfast-notify');

                                                    $original_str = getAscii('merchant_id=merchant_id&merchant_key=merchant_key&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 }}">
                                                
                                                <button type="submit" class="btn btn-success float-right confirm-payfast-order">
                                                    Confirm Order
                                                </button>
                                            </form>
                                        </div>
                                        <!-- END PAYFAST EFT -->
                                    @endforeach
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        $(document).ready(function(){
            var price = $("#totalPrice").data('price'); //get data-price by this syntax
            
            $('#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'); //get data-price by this syntax
                    var deliveryprice = 0;  //get data-price by this syntax
                    var totalPrice = parseFloat(price) + parseFloat(deliveryprice);

                    $('#completePrice').html(totalPrice);
                    $('.completePrice').val(totalPrice);
                    $('.delivery_collection').val('collection');
                    $('.confirm-order').removeAttr('disabled');
                    $('.confirm-payfast-order').removeAttr('disabled');
                }

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

                    var price = $("#totalPrice").data('price'); //get data-price by this syntax
                    var deliveryprice = $("#delivery-price").data('price');  //get data-price by this syntax
                    var totalPrice = parseFloat(price) + parseFloat(deliveryprice);

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

            /* 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();
                    $(".payfast-debit-card").hide();
                }       
            });
            /* END EFT PAYFAST */
        });
    </script>   
@stop

my controller function

public function paymentGateway(Request $request)
{

    if($request->payment_method == 'payfast_eft')
    {
        $process = 'Order Paid';
        $paid = '1';
    }

    if($request->delivery_collection == 'collection')
    {
        $delivery_fee = null;
    }else{
        $delivery_fee = $request->delivery_fee;
    }

    $orders = Order::all();

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

    $validation = Validator::make($request->all(), $this->getRules());

    if($validation->fails())
    {
        return redirect()->route('cart.deliveryConfirmation')
            ->withErrors($validation, 'confirmation_errors')
            ->with('error', 'There were validation errors');
    }
        
    foreach($orders as $order)
    {
        $order = Order::find($order->id)->where('invoice_number', $request->m_payment_id)->first();

        $order->cart = serialize($cart);
        $order->address = $request->delivery_address;
        $order->delivered_date = null;
        $order->delivery_fee = $delivery_fee;
        $order->delivery_option = $request->delivery_collection;
        $order->process = $process;
        $order->order_date = Carbon::now('+2:00');
        $order->payment_method = $request->payment_method;
        $order->paid = $paid;
        $order->order_price = $request->amount;

        $order->save();
    }

    $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 = $request->item_name;
    $item_description = $request->item_description;
    $email_confirmation = '1';
    $confirmation_address = '[email protected]';
    $payment_method = $request->payment_method;
    $signature = $request->signature;

    if($request->payment_method == 'payfast_eft')
    {
        $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);
}

protected function getRules()
{
    return [
        'delivery_collection' => 'required',
        'payment_method' => 'required',
        'delivery_address' => 'required'
    ];
}
10 May
1 week ago

Shiva left a reply on Finding Out If A Table Is Empty

@CHRISTOPHHARMS - Thank you so much that worked

Shiva left a reply on Finding Out If A Table Is Empty

So I have it half working thanks to @dipakrataniagile. So I thought of combining what @dipakrataniagile said with what @christophharms said, but now after I've added the address if a new user comes along and addes their address it would need to do the same thing, so for example:

User 1 has made 2 addresses and the first one he entered has the "selected" field equal 1 and the second address is equal to 0, but now when user 2 comes along the first address that user 2 puts in must be selected = '1'

I hope that made sense

here's the code

public function addPostAddress(Request $request)
    {

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

        $address = new Address();

        $address->user_id = Auth::user()->id;
        $address->fill($this->getSafeAddressInput($request));

        $existingAddress = Address::where('user_id', Auth::user()->id)->get();

        if($address->count() || !$existingAddress)
        {
            $selected = '0';

        }else{
            $selected = '1';
          
        }

        $address->selected = $selected;
        $address->save();

       return redirect()->back();
    }

Shiva started a new conversation Finding Out If A Table Is Empty

I'm trying to find out if a table is empty, I thought that by doing this

 if(!empty($address))
 {
        echo "not empty";
            
 }else{
        echo "empty";
          
 }

it would hit "empty" since the database is empty at the moment, but that isn't happening it keeps going to "not empty".

Here is the full code

public function addPostAddress(Request $request)
    {

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

        $address = new Address();

        $address->user_id = Auth::user()->id;
        $address->fill($this->getSafeAddressInput($request));

        if(!empty($address))
        {
            echo "not empty";
            
        }else{
            echo "empty";
          
        }

        return redirect()->back();
    }
17 Apr
1 month ago

Shiva started a new conversation Getting The First Option To Show

I've created a vue component that has a select drop down option. The problem I'm having is that the first option isn't being shown. The only thing I have is a blank box and when I click on the dropdown all my options are there.

Here is my vue.js

<template>
    <div>
        <form @submit.prevent="submit">
            <div class="row">
                <div class="col-lg-12">
                    <select name="supplier_code" id="supplier_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.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>

16 Apr
1 month ago

Shiva left a reply on ReferenceError: Axios Is Not Defined

yep I had to import axios, because I had removed require('./bootstrap'); from my app.js. Thanks guys

Shiva started a new conversation ReferenceError: Axios Is Not Defined

I'm getting this error when I try to submit a form using vue

ReferenceError: axios is not defined

I don't know why this is happening. Isn't axios already imported in the bootstrap.js that's in the resources/js/ folder?

Here is my vue file

<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>
    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>

Shiva started a new conversation Getting A Child Relation In Vue

In my laravel app I need to loop through the products and grab their code, also the products link to each other because some products are the same just different colour, so I've made it that they have parent product. The problem I'm having is getting the "child" product to show up in my select drop down.

This is how I have it in a normal laravel blade which works

<select class="form-control mx-sm-3 mb-2" id="code" name="code">
    @foreach($parent_product as $parent)
        <option value="{{ $parent->code }}">{{ $parent->code }}</option>
        
        @if(count($parent->parent))
            @foreach($parent->parent as $child)
                <option value="{{ $child->code }}">{{ $child->code }}</option>
            @endforeach
        @endif
    @endforeach
</select>

But now this is what I have in my product.blade.php

<div id="app">
    <code-selection :products="{{ $parent_product }}"></code-selection>
</div>

and this is what I have in 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>

                        <label for="parent-product">Parent Product</label>
                        <select name="parent-product" id="parent-product" class="form-control">
                            <option v-for="product in products" value="product.code">
                                {{ product.code }}


                            </option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        props: [
            'products',
            'selected_parent'
        ],

        mounted() {
            console.log('Component mounted.')
        }
    }
</script>
15 Apr
1 month ago

Shiva started a new conversation The Mix Manifest Does Not Exist.

I'm using vue in my laravel app and everything was working fine, but then I noticed that there was a public folder in my app and I removed it because I didn't want it and then I got this error

The Mix manifest does not exist. 

So I thought maybe it was because I needed to change where the app.js gets saved to after running npm run watch. So I changed it but I still get that error.

This is my webpack.mix.js

let mix = require('laravel-mix');


mix.setPublicPath('dist/')
   .js('resources/js/app.js', 'js')
   .sass('resources/sass/app.scss', 'css');

Shiva left a reply on Changing Where The App.js Goes After Laravel Mix

@TYKUS - It's there now. I think I just had to redo npm install

Shiva left a reply on Changing Where The App.js Goes After Laravel Mix

@TYKUS - Sure. Here it is

let mix = require('laravel-mix');

mix.setPublicPath('dist/')
   .js('resources/js/app.js', 'app.js')
   .sass('resources/sass/app.scss', 'app.css');

Shiva left a reply on Changing Where The App.js Goes After Laravel Mix

@TYKUS - I did that, but I'm still getting the public folder

Shiva started a new conversation Changing Where The App.js Goes After Laravel Mix

I'm trying to change where the app.js goes after I save a js file and run npm run watch the problem is everytime I save a public folder appears and I would like to stop that. I thought that by changing this

mix.js('resources/assets/js/app.js', 'public/js')
   .sass('resources/assets/sass/app.scss', 'public/css');

to

mix.js('resources/assets/js/app.js', 'js')
   .sass('resources/assets/sass/app.scss', 'css');

would work, but I'm still getting the public folder

Shiva left a reply on Vue Component Not Showing Up

@SNAPEY - yep it is. The app.js is coming from resources/assets/js/app.js and the last time stamp is 08:04:38 AM

Shiva left a reply on Vue Component Not Showing Up

@SNAPEY - So I forgot to add app.js to my files. But I'm now getting this error

[Vue warn]: Unknown custom element: <supplier-code-selection> - did you register the component correctly? For recursive components, make sure to provide the "name" option.

but I'm sure I did it correctly though

Shiva started a new conversation Vue Component Not Showing Up

My vue component isn't showing up and I can't see where I went wrong, I'm hoping another set of eyes can point out where I went wrong.

My app.js


/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

Vue.component('table-draggable', require('./components/TableDraggable.vue'));
Vue.component('category-index', require('./components/CategoryIndex.vue'));
Vue.component('active-checkbox', require('./components/ActiveCheckbox.vue'));
Vue.component('supplier-code-selection', require('./components/SupplierCodeSelection.vue'));

const app = new Vue({
    el: '#app'
});

My SupplierCodeSelection.vue

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

                    <div class="card-body">
                        I'm an example component.
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    export default {
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

and my page that the vue is supposed to show

<div id="app">
    <supplier-code-selection></supplier-code-selection>
</div>
07 Apr
1 month ago

Shiva started a new conversation Custom Font For Tinymce In Laravel

I would like to add a custom font to tinymce, but it isn't showing up. I've done this.

<script>
    $(document).ready(function () {
      // ACTIVATING TINYMCE
      tinymce.init({
        selector: "textarea",
        content_css: [' url("../../storage/fonts/Kunstler.ttf")'],
        font_formats: 'Arial Black=arial black,avant garde;Gugi=Gugi, cursive;Times New Roman=times new roman,times;',
      });
    });
    </script>
03 Apr
1 month ago

Shiva started a new conversation Using 'model' In A Form

In the beginning I uses to do this when I created forms.

create.blade.php

@extends('layouts.admin')
@section('content')
    @component('admin.components.products.category-form', [
                    'formUrl' => route('category.store'),
                    'formMethod' => 'POST',
                    'model' => $category
                ])
    @endcomponent
@endsection

and the same thing with edit.blade.php. And then I would create the from in another blade which looks like this

{{ Form::model($model, array('url' => $formUrl, 'method' => $formMethod)) }}

    <div class="form-group">
        {{ Form::label('title', 'Title') }}
        {{ Form::text('title', null, array('class' => 'form-control')) }}
    </div>

    <div class="form-group">
        {{ Form::submit('Save', array('class' => "btn btn-dark btn-lg btn-block")) }}
    </div>
{{ Form::close() }}

What I'm trying to do in not to use the {{ Form::model() }} any more and instead use the html version of the form. What I don't know how to do is, how to incorporate the model side of the form into the html version.

Hope that made sense.

Shiva started a new conversation Getting A Value From A Cell In A Database

In my form I have a textbox that I can add multiple codes to, for example: sup_1, sup_2, sup_3. And I save the as a string in the database.

What I'm struggling with is that I just want to get just one of the codes and then see what is in that row.

I'm doing this

 public function getAddItem($supplier_code)
{
    $product = Product::where('supplier_code', $supplier_code)->get();
    
    dd($product);

    return redirect()->back();
}

So the aim is to look for the supplier_code in the table and grab that info.

15 Mar
2 months ago

Shiva started a new conversation Getting My Query To Look At The Year

I'm trying to have my query do this. Grab all the orders where the order_date equals to the year and where the user_id equals users id. I have maneged to get the year buy I'm struggling to get it check the database for al orders that has that year.

My code

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

    if($request->sort_orders === '2019')
    {
  
        $order_list = Order::where('user_id', $user_id)->get();

        foreach($order_list as $order)
        {
            $year = Carbon::parse($order->order_date)->year;
        }
        
        $orders = Order::where('order_date', $year)->where('user_id', $user_id)->orderBy('order_date', 'desc')->get();
        $orders->transform(function($order, $key){
                $order->cart = unserialize($order->cart);
                return $order;
            });
    }

    return view('public.users.track-orders', compact('menus_child', 'contacts', 'orders', 'order_item'));
}
14 Mar
2 months ago

Shiva left a reply on Getting My Posts To Show The Correct Amount

Looks like I got it working.

I had to replace

return redirect()->route('blog.track-post', compact('posts'));

with

return view('public.track-posts', compact('menus_child', 'contacts', 'posts'));

Shiva left a reply on Getting My Posts To Show The Correct Amount

@DUBBELTJE - Sure.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;

use App\Menu;
use App\Contact;
use App\User;
use App\Post;
use Carbon\Carbon;

use Auth;
use Input;

class PostsController extends Controller
{

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

        $posts = Auth::user()->posts->sortByDesc('post_date');
        

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

    public function sortPosts(Request $request)
    {
        if (Input::get('some-posts') === 'three-months')
        {
            dd('Im in');
            $to = Carbon::now('+2:00');

            $from = $to->copy()->subMonth(3);

            $posts = Post::whereBetween('post_date', [$from, $to])->get();
        }

        return redirect()->route('blog.track-post', compact('posts'));
    }
}

Shiva left a reply on Getting My Posts To Show The Correct Amount

@DUBBELTJE - Nothing happens, all my posts is still showing

Shiva left a reply on Getting My Posts To Show The Correct Amount

@DUBBELTJE - Nothing happens, all my posts are still shown

Shiva left a reply on Getting My Posts To Show The Correct Amount

@DUBBELTJE - dd($request) gives me

Request {#42 ▼
  #json: null
  #convertedFiles: null
  #userResolver: Closure($guard = null) {#208 ▶}
  #routeResolver: Closure() {#210 ▶}
  +attributes: ParameterBag {#44 ▶}
  +request: ParameterBag {#50 ▶}
  +query: ParameterBag {#50 ▶}
  +server: ServerBag {#46 ▶}
  +files: FileBag {#47 ▶}
  +cookies: ParameterBag {#45 ▶}
  +headers: HeaderBag {#48 ▶}
  #content: null
  #languages: null
  #charsets: null
  #encodings: null
  #acceptableContentTypes: null
  #pathInfo: "/account/sort-orders"
  #requestUri: "/account/sort-orders?sort-orders=three_months"
  #baseUrl: ""
  #basePath: null
  #method: "GET"
  #format: null
  #session: Store {#249 ▶}
  #locale: null
  #defaultLocale: "en"
  -isHostValid: true
  -isForwardedValid: true
  basePath: ""
  format: "html"
}

and dd($request->all()) gives me this

array:1 [▼
  "sort-orders" => "three_months"
]

Shiva left a reply on Getting My Posts To Show The Correct Amount

@DUBBELTJE - So what I did was I created a form that has a select menu and if that request value that came from the form is equal to three_months then it does what I need it to

Shiva started a new conversation Getting My Posts To Show The Correct Amount

I'm feeling very silly right now, because I'm sure this is a simple question, but I can't seem to figure it out. What I've done is I've create a page with some posts and you can sort them by a number of months. The problem I'm having is that I can't seem to get them to display only those posts.

My function

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

    $posts = Auth::user()->posts->sortByDesc('post_date');
    

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

public function sortPosts(Request $request)
{
    if($request->all() == 'three_months')
    {
        $to = Carbon::now('+2:00');

        $from = $to->copy()->subMonth(3);

        $posts = Post::whereBetween('post_date', [$from, $to])->get();
    }

    return redirect()->route('blog.track-post', compact('post'));
}

and this is my blade

@extends('layouts.public')
@section('content')
    <div class="content_wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <form action="{{ route('blog.sort-posts') }}">
                        <select class="sort-posts" name="sort-posts">
                            <option selected>Open this select menu</option>
                            <option value="three_months">Last 3 months</option>
                            <option value="six_months">Last 6 months</option>
                            <option value="2019">2019</option>
                        </select>
                    </form>
                </div>
            </div>
        @foreach($posts as $post)
            <div class="row">
                <div class="col-lg-12">
                    <div class="card mt-15">
                        <div class="card-header">
                            <div class="invoice-details">
                                <div>
                                    {{ $post->invoice_number }} | Posted: {{ Carbon\Carbon::parse($post->post_date)->format('d F Y') }}
                                </div>
                            </div>
                        </div>

                        <div class="card-body">
                            <div class="row text-center">
                                {{ $post->title }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        @endforeach
    </div>

    <script>
        $(document).ready(function(){
            $('.sort-posts').change(function(){
                $(this).closest("form").submit();
            });
        })
    </script>
@stop

and my web.php

Route::get('/blog/track-posts', '[email protected]')->name('blog.track-posts');
Route::get('/blog/sort-posts', '[email protected]')->name('blog.sort-posts');
08 Mar
2 months ago

Shiva left a reply on Getting Alternate Rows To Be Different Colors In A Pdf

So I finally have the font and rows sorted, but now when I do things like

<strong>BILL TO:</strong>

it goes back to Times New Roman

Shiva left a reply on Getting Alternate Rows To Be Different Colors In A Pdf

I've changed it to a table, but I'm still having a problem with changing the font.

Shiva left a reply on Getting Alternate Rows To Be Different Colors In A Pdf

@RESIN - I'm not sure how I would be able to add a class name to every odd row when I'm looping through my items

Shiva started a new conversation Getting Alternate Rows To Be Different Colors In A Pdf

I've created a pdf using barryvdh/laravel-dompdf and now I'm trying to style it. I've been sort of successfully on most of it, but I can't get my rows to be different colour. What I would like to happen is that with every odd row it needs to be a certain colour. I'm also having a problem with getting my font to work as well and I'm not understanding why.

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>
            body{
                font-family: Arial;
            }

            .invoice_table .table {
                display: table;
                width: 100%;
            }

            .invoice_table .table .thead {
                display: table-header-group;
            }

            .invoice_table .table .tr {
                display: table-row;
            }

            .invoice_table .table .thead .tr .th {
                display: table-cell;
            }

            .invoice_table .table .thead .th {
                padding: 13px 0 12px;
            }

            .invoice_table .table .tbody {
                display: table-row-group;
            }

            /* CODE TO MAKE THE ROWS A DIFFERENT COLOUR */
            .invoice_table .table .tbody .tr:nth-child(odd){
                background-color: #4C8BF5;
                color: #fff;
            }

            .invoice_table .table .tr .td {
                display: table-cell;
            }

            .invoice_table .table .tbody .td {
                padding: 20px 0;
            }
        </style>
    </head>

    <body style="margin: 0; padding: 0;">
        <div class="invoice_table" style="width: 700px; margin: 30px auto;">
            <div class="table" style="border: 1px solid #000;">
                <div class="thead" style="border: 1px solid #000;">
                    <div class="tr" style="border: 1px solid #000;">
                        <div class="th"></div>
                        <div class="th" style="border: 1px solid #000;">Description</div>
                        <div class="th" style="text-align: center; border: 1px solid #000;">Qty</div>
                        <div class="th" style="text-align: center; border: 1px solid #000;">Unit Price</div>
                        <div class="th" style="text-align: center; border: 1px solid #000;">Total Price</div>
                    </div>
                </div>

                <div class="tbody">
                    @foreach($order_item->items as $item)
                        <div class="tr">
                            <div class="td"></div>
                            <div class="td" style="border: 1px solid #000;">
                                {{ $item['item']['title'] }}
                            </div>
                            <div class="td" style="text-align: center; border: 1px solid #000;">
                                {{ $item['qty'] }}
                            </div>
                            <div class="td" style="text-align: center; border: 1px solid #000;">
                                R {{ $item['item']['price'] }}
                            </div>
                            <div class="td" style="text-align: center; border: 1px solid #000;">
                                R {{ $item['price'] }}
                            </div>
                        </div>
                    @endforeach

                    <div class="tr">
                        <div class="td" rowspan="3" colspan="3" style="padding: 50px 0 5px 0; border: 1px solid #000;"></div>
                        <div class="td" style="text-align: right; padding: 50px 0 5px 0; border: 1px solid #000;">
                            SUBTOTAL:
                        </div>
                        <div class="td" style="text-align: center; padding: 50px 0 5px 0; border: 1px solid #000;">
                            R {{ $order_item->totalPrice }}
                        </div>
                    </div>

                    @if(!empty($order->delivery_fee))
                        <div class="tr">
                            <div class="td" style="text-align: right; padding: 0 0 5px 0; border: 1px solid #000;">
                                DELIVERY FEE:
                            </div>
                            <div class="td" style="text-align: center; padding: 0 0 5px 0; border: 1px solid #000;">
                                R {{ $order->delivery_fee }}
                            </div>
                        </div>
                    @endif

                    <div class="tr">
                        <div class="td" style="text-align: right; padding: 0; border: 1px solid #000;">
                            TOTAL:
                        </div>
                        <div class="td" style="text-align: center; padding: 0; border: 1px solid #000;">
                            R {{ $order->order_price }}
                        </div>
                    </div>
                </div>
            </div>
        </div>  
    </body>
</html>
06 Mar
2 months ago

Shiva left a reply on How To Get The Accordion To Open Or Close Depending If There Is An Error

I solved it by adding this

{{ !$errors->business_errors->any() ? 'show' : '' }}

to

<div id="personal-details" class="collapse show {{ $errors->personal_errors->any() ? 'show' : '' }}" aria-labelledby="headingOne" data-parent="#accordionExample">

and replacing

show {{ $errors->personal_errors->any() ? 'show' : '' }}

Shiva left a reply on Getting Multiple Validations To Work

I got it to work. I kept testing the wrong textbox

Shiva started a new conversation Getting Multiple Validations To Work

In my code I have multiple validations depending on where the user hits. The problem I'm having is that instead of this error showing There were validation errors I'm getting a list of the errors.

Here is the code

public function postPersonalDetails(Request $request)
    {
        $id = Auth::user()->id;

        $user = User::findOrFail($id);
        $existing_password = $user->password;
        $old_email = $user->email;

        if(empty($request->input('existing_password')))
        {
            $password = $existing_password;
        }else{
            if(Hash::check($request->existing_password, $existing_password))
            {
                $password = Hash::make($request->password);
                $request->validate($this->getNewPasswordRule());
            }else{
                return redirect()->back()->with('error', 'Your existing password does not match.');
            }
        }

        if($request->input('email') == $old_email)
        {
            $email = $old_email;

            $old_email_validation = Validator::make($email, $this->getNewEmailRule());

            if($old_email_validation->fails())
            {
                return redirect()->route('account.details')
                                ->withErrors($validation)
                                ->with('error', 'There were validation errors');
            }
        }else{
            $email = $request->email;
            $email_validation = Validator::make($email, $this->getNewEmailRule());

            if($email_validation->fails())
            {
                return redirect()->route('account.details')
                                ->withErrors($validation)
                                ->with('error', 'There were validation errors');
            }
        }


        $validation = Validator::make($request->all(), $this->getRules());

        if($validation->fails())
        {
            return redirect()->route('account.details')
                            ->withErrors($validation)
                            ->with('error', 'There were validation errors');
        }

        $user->email = $email;
        $user->password = $password;
        $user->salutation = $request->salutation;

        $user->name = $request->name;
        $user->surname = $request->surname;
        $user->phone_number = $request->phone_number;
        $user->telephone_2 = $request->telephone_2;
        $user->save();

        return redirect()->route('account.details')->with('success', 'Details saved successfully');
    }

Shiva started a new conversation How To Get The Accordion To Open Or Close Depending If There Is An Error

I've created a page where there is an accordion and in the first accordion there is the personal details and in the second accordion there is business details, the personal accordion will always be open when you land on the page or when you have successfully entered the data. The problem I'm having is that if there is an error in the business accordion then I want the personal accordion to close and the business was to stay open.

My details.blade.php

@extends('layouts.public')
@section('content')
    <div class="content_wrapper">
        <div class="row">
            <div class="col-lg-12">
                <div class="row">
                    <div class="col-lg-12 mt-15">
                        @if($message = Session::get('success'))
                            <div class="alert alert-success" role="alert">
                                {{ $message }}
                            
                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                        @endif

                        @if($message = Session::get('error'))
                            <div class="alert alert-danger" role="alert">
                                {{ $message }}

                                <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                                    <span aria-hidden="true">&times;</span>
                                </button>
                            </div>
                        @endif
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 mt-60">
                <div class="accordion" id="accordionExample">
                    <div class="card border-dark">
                        <div class="card-header bg-dark" id="headingOne">
                            <h2 class="mb-0">
                                <button class="btn btn-link text-white" type="button" data-toggle="collapse" data-target="#personal-details" aria-expanded="true" aria-controls="collapseOne">
                                    Personal Details
                                </button>
                            </h2>
                        </div>

                        <div id="personal-details" class="collapse show {{ $errors->personal_errors->any() ? 'show' : '' }}" aria-labelledby="headingOne" data-parent="#accordionExample">
                            <div class="card-body">
                                @include('public.users.partials.personal-details')
                            </div>
                        </div>
                    </div>

                    <div class="card border-dark">
                        <div class="card-header bg-dark" id="headingTwo">
                            <h2 class="mb-0">
                                <button class="btn btn-link collapsed text-white" type="button" data-toggle="collapse" data-target="#business-details" aria-expanded="false" aria-controls="business-details">
                                    Business Details
                                </button>
                            </h2>
                        </div>
                        
                        <div id="business-details" class="collapse {{ $errors->business_errors->any() ? 'show' : '' }}" aria-labelledby="headingTwo" data-parent="#accordionExample">
                            <div class="card-body">
                                @include('public.users.partials.business-details')
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
@stop

and this is my controller

public function postBusinessDetails(Request $request)
{
    $id = Auth::user()->id;
    $user = User::findOrFail($id);

    $validation = Validator::make($request->all(), $this->getBusinessRules());

    if($validation->fails())
    {
        return redirect()->route('account.details')
                        ->withErrors($validation, 'business_errors')
                        ->with('error', 'There were validation errors');
    }
   

    $user->fill($this->getSafeBusinessInput($request));

    $user->save();

    return redirect()->route('account.details')->with('success', 'Details saved successfully');
}
05 Mar
2 months ago

Shiva started a new conversation How To Only Submit Password When Typed

So I'm trying to create a page where once the user has registered they can then add more info and update their password should they need to. The problem I'm having is that, when the user submits the form without doing anything to the password field I get the

Integrity constraint violation: 1048 Column 'password' cannot be null

What I would like to know is, if there is a way to submit the form without touching the password field unless the user clicks on the textbox. I want to leave the password field blank so that when they try to update their password they first have to enter their existing password and then the password is checked against the database to see if it is correct before updating the password.

Here is my form

<form action="{{ route('post.personal-details') }}" method="post">
    @csrf
    <div class="row">
        <div class="col">
            <div class="form-group"> 
                <h1>Change your email address</h1>
                <label for="email">Email Address</label>
                <input type="text" name="email" id="email" class="form-control" value="{{ $user->email }}">

                <label for="email_confirmation">Confirm Email Address</label>
                <input type="text" name="email_confirmation" id="email_confirmation" class="form-control">
            </div>
        </div>

        <div class="col">
            <div class="form-group">
                <h1>Change your password</h1>
                <label for="existing_password">Existing Password</label>
                <input type="text" name="existing_password" id="existing_password" class="form-control" >

                <label for="password">New Password</label>
                <input type="text" name="password" id="password" class="form-control">

                <label for="confirm_password">Confirm New Password</label>
                <input type="text" name="confirm_password" id="confirm_password" class="form-control">
            </div>
        </div>
    </div>
</form>

and here is my controller function

public function postPersonalDetails(Request $request)
{
    $id = Auth::user()->id;

    $user = User::findOrFail($id);

    $input = $this->getInput($request);

    $user->fill($input);
    $user->save();

    return redirect()->route('account.details')->with('success', 'Details saved successfully');
}

protected function getInput(Request $request)
{
    return $request->only([
        'name',
        'surname',
        'email',
        'password',
        'phone_number',
        'telephone_2',
        'trading_name',
        'company_name',
        'vat_number',
        'ck_number',
        'office_number',
        'work_email',
        'office_address',
        'contact_person',
    ]);
}
04 Mar
2 months ago

Shiva started a new conversation If Something Exists In A Table

Does laravel have something that can do this:

if(exist($order_number))
{
    // I WILL DO SOMETHING
}else{
    //  I WILL DO NOTHING
}
14 Feb
3 months ago

Shiva started a new conversation Getting The Str::ascii To Work On Blade

I'm tring to get a string to be converted to ascii, so I came across this Str::ascii but I can't get it to work in my blade template.

here is my code

<?php
    $success = url('payfast-success');
    $cancel = url('payfast-cancel');

    $test = Str::ascii($success);

    dd($test);
?>

Shiva left a reply on Converting String To Ascii Hex

@TOKOIWESLEY - That didn't work it only gave me payfast-success

Shiva started a new conversation Converting String To Ascii Hex

I'm trying to convert certain symbols in my string into ascii hex. I've been looking but I can't seem to find anything.

The string that I need converted is this

$success = url('payfast-success');
$cancel = url('payfast-cancel');

merchant_id=10000100&merchant_key=46f0cd694581a&return_url='.$success.'&cancel_url='.$cancel.'&m_payment_id=01AB&amount='.$total.'&item_name=Test Item&item_description=A test product&email_confirmation=1&[email protected]&payment_method=eft

and the output is suppose to look like this

merchant_id=10000100&merchant_key=46f0cd694581a&return_url=http%3A%2F%2Flaravel-shop.test%2Fpayfast-success&cancel_url=http%3A%2F%2Flaravel-shop.test%2Fpayfast-cancel&m_payment_id=01AB&amount=1.05&item_name=Test+Item&item_description=A+test+product&email_confirmation=1&confirmation_address=test%40test.com&payment_method=eft

This is what my output looks like at the moment

merchant_id=10000100&merchant_key=46f0cd694581a&return_url=http://laravel-shop.test/payfast-success&cancel_url=http://laravel-shop.test/payfast-cancel&m_payment_id=01AB&amount=1.05&item_name=Test Item&item_description=A test product&email_confirmation=1&[email protected]&payment_method=eft