stephen waweru's avatar

how to use auth check for a retuning customer in ecommerce laravel 8

I am creating an eCommerce web platform where users will be able to create an account in order to proceed to the checkout page. what i want to achieve is when a buyer returns to buy again in the on login they won't be able to add their shipping address but rather they will see their previous shipping address with an option of changing it else if they are a new buyer they will see the shipping address form.that is if the buyer is a new buyer they will see the shipping address form else if they are a returning buyer they will see the shipping details they entered in their previous purchase. i have tried to achieve this using check logic but it doesn't work rather it produces an error for a new buyer Trying to get property 'shipcharges' of non-object..the addresses variable represents the addresses table...which logic can i use to achieve this...

						@if (Auth::user()->id!==$addresses->user_id)
                                <div class="card border-2 shadow p-3 mb-5 bg-white rounded">
                                    <div class="card-header" style="position: relative;">
                                        <p class="card-text text-dark">SHIPPING DETAILS</p>
                                        <a href="#" class="float-right" style="position: absolute; 
                                        right: 25px;
                                        top: 25px;">edit</a>
                                        <hr class="my-0">
                                    </div>
                                    <div class="card-body">
                                        <div class="row justify-content-between">
                                            <div class="col-auto mt-0">
                                                <p><b>
                                                    {{ $deliveriesdata->shipcharges->county }}
                                                </b></p>
                                            </div>
                                            <br>
                                            <div class="col-auto">
                                                <p><b>{{ $deliveriesdata->towns->town }},{{ $deliveriesdata->towns->pickuppoint }}</b></p>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            @else
                                <form method="post" action="{{ route('address.store') }}" class="form">
                                    @csrf
                                    <div class="row">
                                        <div class="col-md-6">
                                            <div class="checkout-form-list">
                                                <label>First Name <span class="required">*</span></label>
                                                <input type="text" placeholder="First Name" name="first_name" class="form-control input-md {{ $errors->has('first_name') ? 'error' : '' }}" required/>
                                            </div>
                                        </div>
                                        <div class="col-md-6">
                                            <div class="checkout-form-list">
                                                <label>Last Name <span class="required">*</span></label>
                                                <input type="text" placeholder="Last Name" name="last_name" class="form-control input-md {{ $errors->has('last_name') ? 'error' : '' }}" required/>
                                            </div>
                                        </div>
                                    </div>
                                    
                                    <div class="col-md-12">
                                        <div class="checkout-form-list">
                                            <label>Company Name</label>
                                            <input type="text" placeholder="Your Company Name" name="company_name" />
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="checkout-form-list">
                                            <label>Phone <span class="required">*</span></label>
                                            <input type="text" placeholder="Your Phone Number" name="phone" class="form-control input-md {{ $errors->has('phone') ? 'error' : '' }}" required/>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="country-select">
                                            <label>County <span class="required">*</span></label>
                                            <select id="cty_id" class="county form-control" name="countyname">
                                                <option value="0" disabled="true" selected="true">Choose Your County</option>
                                                    @foreach($delivaddresses as $address)
                                                        <option value="{{ $address->id }}">{{ $address->county }}</option>
                                                    @endforeach
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="checkout-form-list">
                                            <label>Town / City <span class="required">*</span></label>
                                            <select class="town form-control" name="cityname">
                                                <option value=" " disabled="true" selected="true">Select Your City</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="col-md-12">
                                        <div class="checkout-form-list">
                                            <label>Pick Up Point <span class="required">*</span></label>
                                            <input type="text" name="street_address" class="pickup_point form-control input-md" value=" " />
                                        </div>
                                    </div>
                                    <button type="submit" class="btn btn-dark btn-block">Submit</button>
                                </form>
                            @endif
0 likes
4 replies
Snapey's avatar

did you create a User when they placed their first order?

1 like
stephen waweru's avatar

@Snapey still i havent placed the order..i want he data to be extracted from their addresses table

Snapey's avatar

@stephen waweru you are not being clear. They return to your site but somehow are authenticated?

stephen waweru's avatar

@snapey yes they have to get authenticated first...but I have figured out something I can use a relationship in the orders model to get their shipping address...then use checks to show their details or the shipping address form?

Please or to participate in this conversation.