nicwek

nicwek

Member Since 2 Months Ago

Experience Points
1,360
Total
Experience

3,640 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
1
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

Level 1
1,360 XP
Jul
16
2 weeks ago
Activity icon

Replied to Extending A Class Several Times

Thanks alot, guys for the helpful responses. My problem is resolved.

Activity icon

Started a new Conversation Extending A Class Several Times

I am trying to implement extends to a user class two times, how can i do that correctly in laravel?

class User extends \TCG\Voyager\Models\User extends Authenticatable implements MustVerifyEmail
Jul
09
3 weeks ago
Activity icon

Started a new Conversation Using Ajax To Filter Brands In Laravel Ecommerce

I am following up on an online tutorial to explain on how to implement product brand filters in a laravel e-commerce. The filter uses ajax and checkboxes where a user clicks on a checkbox to filter according to the brand. The filter works well when checking the checkboxes, the issue comes in when i want to uncheck and go back to no filter. The page called in the controller duplicates itself in the window where filtering occurs. I have tried finding a solution for several days now, I will surely appreciate all effort. Or alternatively is there an easier way to implement product filtering in ecommerce without reload with checkboxes instead of using ajax.

Here is my controller function

public function allproducts(Request $request)
    {
        if ($request->ajax() && isset($request->start)) {
            $start = $request->start; // min price value
            $end = $request->end; // max price value

            $products = DB::table('products')
                ->where('price', '>=', $start)->where('price', '<=', $end)->orderby('price', 'ASC')->paginate(6);

            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.product', ['allProducts' => $products]);

        } else if (isset($request->brand)) {

            $brand = $request->brand; //brand

            $products = DB::table('products')->whereIN('brand', explode(',', $brand))->paginate(6);
            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.product', ['allProducts' => $products]);

        } else {

            $products = DB::table('products')->paginate(12);
            $categories = Category::whereNull('parent_id')->get();
            return view('product.all', ['allProducts' => $products, 'categories' => $categories]);

        }

    }
Activity icon

Started a new Conversation Using Ajax To Filter Brands In Laravel Ecommerce

I am following up on an online tutorial to explain on how to implement product brand filters in a laravel e-commerce. The filter uses ajax and checkboxes where a user clicks on a checkbox to filter according to the brand. The filter works well when checking the checkboxes, the issue comes in when i want to uncheck and go back to no filter. The page called in the controller duplicates itself in the window where filtering occurs. I have tried finding a solution for several days now, I will surely appreciate all effort. Or alternatively is there an easier way to implement product filtering in ecommerce without reload with checkboxes instead of using ajax.

Here is my controller function

public function allproducts(Request $request)
    {
        if ($request->ajax() && isset($request->start)) {
            $start = $request->start; // min price value
            $end = $request->end; // max price value

            $products = DB::table('products')
                ->where('price', '>=', $start)->where('price', '<=', $end)->orderby('price', 'ASC')->paginate(6);

            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.product', ['allProducts' => $products]);

        } else if (isset($request->brand)) {

            $brand = $request->brand; //brand

            $products = DB::table('products')->whereIN('brand', explode(',', $brand))->paginate(6);
            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.product', ['allProducts' => $products]);

        } else {

            $products = DB::table('products')->paginate(12);
            $categories = Category::whereNull('parent_id')->get();
            return view('product.all', ['allProducts' => $products, 'categories' => $categories]);

        }

    }
Jul
07
4 weeks ago
Activity icon

Replied to Ajax Refresh Duplicates Window

Thanks, guys for your inputs which have been really so helpful. I actually realized where the fault was in but i don't know how to come out of the problem...I have been implementing the ajax by returning a view containing products only which is product.product, when i uncheck all the brands meaning the ajax function is not being used, i get duplicated HTML of my default view product.all. This is my controller and view

public function allproducts(Request $request)
    {
        if ($request->ajax() && isset($request->start)) {
            $start = $request->start; // min price value
            $end = $request->end; // max price value

            $products = DB::table('products')
                ->where('price', '>=', $start)->where('price', '<=', $end)->orderby('price', 'ASC')->paginate(6);

            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.product', ['allProducts' => $products]);

        } else if (isset($request->brand)) {

            $brand = $request->brand; //brand

            $products = DB::table('products')->whereIN('brand', explode(',', $brand))->paginate(6);
            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.product', ['allProducts' => $products]);

        } else {
            //$products = Product::where('id', $id)->paginate(10);
            //$products = Product::paginate(12);
            $products = Product::paginate(12);
            $categories = Category::whereNull('parent_id')->get();
            //response()->json($products); //return to ajax
            //response()->json($categories); //return to ajax

            return view('product.all', ['allProducts' => $products, 'categories' => $categories]);

        }
    }

The view

@extends('layouts.front')

@section('content')



<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>

    $(function () {
        $("#slider-range").slider({
            range: true,
            min: 0,
            max: 100000,
            values: [15, 1000],
            slide: function (event, ui) {

                $("#amount_start").val(ui.values[ 0 ]);
                $("#amount_end").val(ui.values[ 1 ]);
                var start = $('#amount_start').val();
                var end = $('#amount_end').val();

                $.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '',
                    data: "start=" + start + "& end=" + end,
                    success: function (response) {
                        console.log(response);
                        $('#updateDiv').html(response);
                    }
                });
            }
        });

        $('.try').click(function(){
            var brand = [];
            $('.try').each(function(){
                if($(this).is(":checked")){

                    brand.push($(this).val());
                }
                
              
            });
            Finalbrand  = brand.toString();

            $.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '',
                    data: "brand=" + Finalbrand,
                    success: function (response) {
                        console.log(response);
                        $('#updateDiv').html(response);
                    }
                });

        });
       });

</script>

<div class="ps-breadcrumb">
    <div class="ps-container">
        <ul class="breadcrumb">
            @foreach (Breadcrumbs::current() as $crumbs)
                @if ($crumbs->url() && !$loop->last)
                    <li class="breadcrumb-item">
                        <a href="{{ $crumbs->url() }}">
                            {{ $crumbs->title() }}
                        </a>
                    </li>
                @else
                    <li class="breadcrumb-item active">
                        {{ $crumbs->title() }}
                    </li>
                @endif
            @endforeach
        </ul>
    </div>
</div>
















    <div class="ps-page--shop" id="shop-sidebar">
        <div class="container">
            <div class="ps-layout--shop">
                <div class="ps-layout__left">
                    <aside class="widget widget_shop">
                        <h4 class="widget-title">Categories</h4>
                        <ul class="ps-list--categories">
                            @foreach($categories as $category)
                            
                            <li class="current-menu-item menu-item-has-children">
                            <a href="{{route('products.index', ['category_id' => $category->id])}}" style="line-height: 27px;">{{$category->name}}{{--<span class="sub-toggle"><i class="fas fa-angle-down"></i></span>--}}
                                @php
                                $children = TCG\Voyager\Models\Category::where('parent_id', $category->id)->get();
                            @endphp

                       {{[email protected]($children->isNotEmpty())
                        <div class="category-menu-dropdown">

                            @foreach ($children as $child)
                                <!--<div class="category-dropdown-style category-common3">-->
                                    <ul class="submenu">
                                        <li class="current-menu-item"><a href="{{route('products.index', ['category_id' => $child->id])}}">
                                        {{$child->name}}
                                        </a></li>
                                    </ul>
                                <!--</div>-->
                            @endforeach
                        </div>
                        @endif--}}          
                            </li>
                            @endforeach
                        </ul>
                    </aside>

                    <aside class="widget widget_shop">
                        <h4 class="widget-title">BY BRANDS</h4>
                        <form class="ps-form--widget-search" action="do_action" method="get">
                            <input class="form-control" type="text" placeholder="">
                            <button><i class="icon-magnifier"></i></button>
                        </form>

                        <figure class="ps-custom-scrollbar" data-height="250">
                            
                               <?php use App\Product; ?>
                               <?php $brands = Product::select('brand')->groupBy('brand')->get(); ?>

                               @foreach ($brands as $brand )

                               <ul class="list-unstyled" style="line-height: 2; cursor:pointer;">   
                                   <li><input  id="brand" class="try" value="{{ $brand->brand}}"  class="try" type="checkbox">&nbsp;&nbsp;<span>{{ ucwords($brand->brand) }}</span>&nbsp;&nbsp;({{App\Product::where('brand',$brand->brand)->count()}})</li>  
                               </ul>

                                @endforeach

                        </figure>
                        <figure>
                            <h4 class="widget-title">By Price</h4>
                            <div class="ps-slider" data-default-min="13" data-default-max="1300" data-max="1311" data-step="100" data-unit="$"></div>
                            <p class="ps-slider__meta">Price:<span class="ps-slider__value ps-slider__min"></span>-<span class="ps-slider__value ps-slider__max"></span></p>

                            <!--<div id="slider-range"></div>
                                    <b><input size="2" type="text" id="amount_start" name="start_price" value="15" readonly="readonly"></b>
                                    <b><input size="2" type="text" id="amount_end" name="end_price" value="65" readonly="readonly"></b>-->


                        </figure>
                        <figure>
                            <h4 class="widget-title">By Price</h4>
                            <div class="ps-checkbox">
                                <input class="form-control" type="checkbox" id="review-1" name="review">
                                <label for="review-1"><span><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i></span><small>(13)</small></label>
                            </div>
                            <div class="ps-checkbox">
                                <input class="form-control" type="checkbox" id="review-2" name="review">
                                <label for="review-2"><span><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star"></i></span><small>(13)</small></label>
                            </div>
                            <div class="ps-checkbox">
                                <input class="form-control" type="checkbox" id="review-3" name="review">
                                <label for="review-3"><span><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star"></i><i class="fa fa-star"></i></span><small>(5)</small></label>
                            </div>
                            <div class="ps-checkbox">
                                <input class="form-control" type="checkbox" id="review-4" name="review">
                                <label for="review-4"><span><i class="fa fa-star rate"></i><i class="fa fa-star rate"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i></span><small>(5)</small></label>
                            </div>
                            <div class="ps-checkbox">
                                <input class="form-control" type="checkbox" id="review-5" name="review">
                                <label for="review-5"><span><i class="fa fa-star rate"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i><i class="fa fa-star"></i></span><small>(1)</small></label>
                            </div>
                        </figure>
                        <figure style="display: none;">
                            <h4 class="widget-title">By Color</h4>
                            <div class="ps-checkbox ps-checkbox--color color-1 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-1" name="size">
                                <label for="color-1"></label>
                            </div>
                            <div class="ps-checkbox ps-checkbox--color color-2 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-2" name="size">
                                <label for="color-2"></label>
                            </div>
                            <div class="ps-checkbox ps-checkbox--color color-3 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-3" name="size">
                                <label for="color-3"></label>
                            </div>
                            <div class="ps-checkbox ps-checkbox--color color-4 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-4" name="size">
                                <label for="color-4"></label>
                            </div>
                            <div class="ps-checkbox ps-checkbox--color color-5 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-5" name="size">
                                <label for="color-5"></label>
                            </div>
                            <div class="ps-checkbox ps-checkbox--color color-6 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-6" name="size">
                                <label for="color-6"></label>
                            </div>
                            <div class="ps-checkbox ps-checkbox--color color-7 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-7" name="size">
                                <label for="color-7"></label>
                            </div>
                            <div class="ps-checkbox ps-checkbox--color color-8 ps-checkbox--inline">
                                <input class="form-control" type="checkbox" id="color-8" name="size">
                                <label for="color-8"></label>
                            </div>
                        </figure>
                        <figure class="sizes" style="display: none;">
                            <h4 class="widget-title">BY SIZE</h4><a href="#">L</a><a href="#">M</a><a href="#">S</a><a href="#">XL</a>
                        </figure>
                    </aside>
                </div>
                <div class="ps-layout__right">
                    <div class="ps-shopping ps-tab-root">
                        <div class="ps-shopping__header">
                             
                            <p><strong> {{$allProducts->total()}}</strong> Products found</p>
                            <div class="ps-shopping__actions">
                                <select class="ps-select" data-placeholder="Sort Items">
                                    <option>Sort by latest</option>
                                    <option>Sort by popularity</option>
                                    <option>Sort by average rating</option>
                                    <option>Sort by price: low to high</option>
                                    <option>Sort by price: high to low</option>
                                </select>
                                <div class="ps-shopping__view">
                                    <p>View</p>
                                    <ul class="ps-tab-list">
                                        <li class="active"><a href="#tab-1"><i class="fas fa-th"></i></a></li>
                                        <li><a href="#tab-2"><i class="fas fa-list-ul"></i></a></li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                        <div class="ps-tabs" id="updateDiv">
                            
                            <div class="ps-tab active" id="tab-1">
                                <div class="ps-shopping-product">
                                    <div class="row">
                                        @foreach ($allProducts as $product)
                                        <div class="col-xl-3 col-lg-4 col-md-4 col-sm-6 col-6 ">
                                            <div class="ps-product">
                                                <div class="ps-product__thumbnail"><a href="{{url('product/'.$product->id)}}"><img src="{{asset('storage/'.$product->cover_img)}}" alt=""></a>
                                                    <ul class="ps-product__actions">
                                                        <li><a href="{{route('cart.add', $product->id)}}" data-toggle="tooltip" data-placement="top" title="Add to Cart"><i class="fas fa-shopping-bag"></i></a></li>
                                                       {{-- <li><a href="{{route('quick')}}" data-placement="top" title="Quick View" data-toggle="modal" data-target="#product-quickview"><i class="far fa-eye"></i></a></li>
                                                        <li><a href="{{route('addToWishList')}}" data-toggle="tooltip" data-placement="top" title="Add to Whishlist"><i class="far fa-heart"></i></a></li>
                                                        <li><a href="#" data-toggle="tooltip" data-placement="top" title="Compare"><i class="far fa-chart-bar"></i></a></li>--}}
                                                    </ul>
                                                </div>

                                                
                                            <div class="ps-product__container"><a class="ps-product__vendor" href=""></a>
                                                    <div class="ps-product__content"><a class="ps-product__title" href="{{url('product/'.$product->id)}}">{{$product->name}}</a>
                                                        <p class="ps-product__price"><b>KES {{$product->price}}</b></p>
                                                    </div>
                                                <div class="ps-product__content hover"><a class="ps-product__title" href="{{url('product/'.$product->id)}}">{{$product->name}}</a>
                                                        <p class="ps-product__price"><b>KES {{$product->price}}</b></p>
                                                    </div>
                                                    {{--<a href="{{route('cart.add', $product->id)}}" data-toggle="tooltip" data-placement="top" title="Add to Cart"><i class="fas fa-shopping-cart"></i></a>--}}
                                                </div>
                                            </div>
                                        </div>
                                        @endforeach

                                    </div>
                                </div>
                                
                                <div class="ps-pagination">
                                    <ul class="pagination">
                                        {{$allProducts->links()}}
                                    </ul>
                                </div>
                            </div>
                            <div class="ps-tab" id="tab-2">
                                <div class="ps-shopping-product">
                                    @foreach ($allProducts as $product)
                                        
                                   
                                    <div class="ps-product ps-product--wide">
                                        <div class="ps-product__thumbnail"><a href="{{url('product/'.$product->id)}}"><img src="{{asset('storage/'.$product->cover_img)}}" alt=""></a>
                                        </div>
                                        <div class="ps-product__container">
                                            <div class="ps-product__content"><a class="ps-product__title" href="{{url('product/'.$product->id)}}">{{$product->name}}</a>
                                            
                                                <ul class="ps-product__desc">
                                                    <li>{{$product->details}}</li>
                                                </ul>
                                            </div>
                                            <div class="ps-product__shopping">
                                                <p class="ps-product__price text-center">KES {{$product->price}}</p><a class="ps-btn" href="{{route('cart.add', $product->id)}}">Add to cart</a>
                                                <ul class="ps-product__actions">
                                                    
                                                    <li><a href="#"><i class="icon-chart-bars"></i> Compare</a></li>
                                                </ul>
                                            </div>
                                        </div>
                                    </div>
                                    @endforeach
                                </div>
                                
                                
                                <div class="ps-pagination">
                                    <ul class="pagination">
                                        {{$allProducts->links()}}
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>


    
    

    @endsection
Jul
06
4 weeks ago
Activity icon

Replied to Ajax Refresh Duplicates Window

Thanks @tinfoilman for the reply. But, when i implement the splice, the page now even duplicates during the checking of the checkbox.

Activity icon

Started a new Conversation Ajax Refresh Duplicates Window

I am implementing ajax filter to filter product brands on a web page. The brand filter is implemented using checkboxes. The filter works perfectly when checking but when unchecking brands, the window duplicates itself. All the help will be sincerely appreciated.

Here is my code:

        $('.try').click(function(){
            var brand = [];
            $('.try').each(function(){
                if($(this).is(":checked")){

                    brand.push($(this).val());
                }
            });
            Finalbrand  = brand.toString();

            $.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '',
                    data: "brand=" + Finalbrand,
                    success: function (response) {
                        console.log(response);
                        $('#updateDiv').html(response);
                    }
                });

        });
Jul
03
1 month ago
Activity icon

Replied to Displaying Markdown Content In Laravel Voyager

Thanks a lot, @bobbybouwmann for help. However, I did not use the Graham Campbell package but your suggestion gave me the insight to solve the problem. I used michelf/php-markdown package which turned the markdown content to HTML.

Activity icon

Replied to Displaying Markdown Content In Laravel Voyager

Basically, how can i use markdown editor to display content to front end? because currently, it is not giving me the expected results

Activity icon

Replied to Displaying Markdown Content In Laravel Voyager

Thanks, @bobbybouwmann for the response. However, that is not the issue at the moment. I already have the type set to markdown editor. When i edit heading in the backend using the markdown editor in the frontend i get '#text', where 'text' is the intended heading. Could you be having a solution for this?

Activity icon

Started a new Conversation Displaying Markdown Content In Laravel Voyager

Is there a way of enabling laravel voyager display content as intended. For instance, i am using markdown for trying to display a heading from the backend and in the front end am getting #heading and not the capitalised bold heading. Could anyone be knowing a way around this? All the help will be extremely appreciated.

Jun
30
1 month ago
Activity icon

Started a new Conversation Displaying List Items In Laravel Voyager

I am trying to display a list of product specifications from backend to frontend using voyager. I have tried using rich text box but in the front end, it displays HTML tags. Could someone be knowing a workaround to implement this easily using voyager?

Jun
29
1 month ago
Activity icon

Started a new Conversation Displaying List Items In Laravel Voyager

I am trying to display a list of product specifications from backend to frontend using voyager. I have tried using rich text box but in the front end, it displays HTML tags. Could someone be knowing a workaround to implement this easily using voyager?

Jun
17
1 month ago
Activity icon

Replied to Load Already Installed Package Using Composer

Thanks @snapey, for your reply which really helped alot. Although, i had to call the required package differently using composer, i used php -d memory_limit=-1 C:/laragon/bin/composer/composer.phar require realrashid/sweet-alert and it worked. Where again C:/laragon/bin/composer/composer.phar was route to composer.phar file

Activity icon

Replied to Load Already Installed Package Using Composer

@punksolid, it has been happening in the local development environment

Jun
16
1 month ago
Activity icon

Started a new Conversation Load Already Installed Package Using Composer

I am still finding my way round laravel and i have installed some packages in an another project using composer and when i trying installing the same packages in a current project, i get this error: Fatal error: Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://C:/ProgramData/ComposerSetup/bin/composer.phar/src/Composer/DependencyResolver/RuleWatchGraph.php on line 52

How can i install or load this packages without getting this error?

Jun
13
1 month ago
Activity icon

Replied to Share Laravel Project With Ngrok In Laragon

Thanks for the reply @monstajamss. I tried it your way and it still does not work

Jun
12
1 month ago
Activity icon

Started a new Conversation Share Laravel Project With Ngrok In Laragon

I am using Laragon 4.0.16 to do a project and i am quite new to it. Could someone know the procedure of sharing a project to Ngrok using Laragon 4.0.16, i have tried checking content on this to no success, plus when i set up my Laragon to ngrok, i am redirected to Laragon root.

Jun
09
1 month ago
Activity icon

Awarded Best Reply on Ajax Filter Not Working

Thanks, guys for your input. I actually solved it. I just cut the products displaying section and placed it in another blade view file and the filters worked.

Activity icon

Replied to Ajax Filter Not Working

Thanks, guys for your input. I actually solved it. I just cut the products displaying section and placed it in another blade view file and the filters worked.

Jun
08
1 month ago
Activity icon

Replied to Ajax Filter Not Working

Thanks @jlrdw for the response. I removed the views and still i get nothing on the display display

Activity icon

Started a new Conversation Ajax Filter Not Working

I have implemented ajax to filter brands on my site, such that when i check the checkbox the filter is implemented without reloading. The issue is when i click the brand to be filtered my page loads and bring nothing to display. When i uncheck, the same happens, the site just loads. When i damp and die, i get the expected result but when i remove the dd i get nothing. Kindly assist.

My Controller

public function allproducts(Request $request)
    {
        if ($request->ajax() && isset($request->start)) {
            $start = $request->start; // min price value
            $end = $request->end; // max price value

            $products = DB::table('products')
                ->where('price', '>=', $start)->where('price', '<=', $end)->orderby('price', 'ASC')->paginate(6);

            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.all', ['allProducts' => $products, 'categories' => $categories]);

        } else if (isset($request->brand)) {

            $brand = $request->brand; //brand

            $products = DB::table('products')->whereIN('brand', explode(',', $brand))->paginate(6);
            $categories = Category::whereNull('parent_id')->get();
            //dd($products);
            response()->json($products); //return to ajax
            response()->json($categories); //return to ajax
            return view('product.all', ['allProducts' => $products, 'categories' => $categories]);

        } else {

            $products = Product::take(50)->paginate(10);
            $categories = Category::whereNull('parent_id')->get();

            return view('product.all', ['allProducts' => $products, 'categories' => $categories]);

        }
    }

The ajax function

<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>

    $(function () {
        $("#slider-range").slider({
            range: true,
            min: 0,
            max: 100000,
            values: [15, 1000],
            slide: function (event, ui) {

                $("#amount_start").val(ui.values[ 0 ]);
                $("#amount_end").val(ui.values[ 1 ]);
                var start = $('#amount_start').val();
                var end = $('#amount_end').val();

                $.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '',
                    data: "start=" + start + "& end=" + end,
                    success: function (response) {
                        console.log(response);
                        $('#updateDiv').html(response);
                    }
                });
            }
        });

        $('.try').click(function(){
            var brand = [];
            $('.try').each(function(){
                if($(this).is(":checked")){

                    brand.push($(this).val());
                }
            });
            Finalbrand  = brand.toString();

            $.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '',
                    data: "brand=" + Finalbrand,
                    success: function (response) {
                        console.log(response);
                        $('#updateDiv').html(response);
                    }
                });

        });
       });

</script>

The View

@extends('layouts.front')

@section('content')
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>

    $(function () {
        $("#slider-range").slider({
            range: true,
            min: 0,
            max: 100000,
            values: [15, 1000],
            slide: function (event, ui) {

                $("#amount_start").val(ui.values[ 0 ]);
                $("#amount_end").val(ui.values[ 1 ]);
                var start = $('#amount_start').val();
                var end = $('#amount_end').val();

                $.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '',
                    data: "start=" + start + "& end=" + end,
                    success: function (response) {
                        console.log(response);
                        $('#updateDiv').html(response);
                    }
                });
            }
        });

        $('.try').click(function(){
            var brand = [];
            $('.try').each(function(){
                if($(this).is(":checked")){

                    brand.push($(this).val());
                }
            });
            Finalbrand  = brand.toString();

            $.ajax({
                    type: 'get',
                    dataType: 'html',
                    url: '',
                    data: "brand=" + Finalbrand,
                    success: function (response) {
                        console.log(response);
                        $('#updateDiv').html(response);
                    }
                });

        });
       });

</script>




        <!-- Breadcrumb Area -->
        <section class="breadcrumb-area">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="breadcrumb-box text-center">
                            <ul class="list-unstyled list-inline">
                                <li class="list-inline-item"><a href="{{route('home') }}">Home</a></li>
                                <li class="list-inline-item"><span>||</span>PRODUCTS</li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- End Breadcrumb Area -->

        <!-- Category Area -->
        <section class="category">
            <div class="container">
                <div class="row">
                    <div class="col-md-3">
                        <div class="category-box">
                            <div class="sec-title">
                                <h6>Categories</h6>
                            </div>
                            <!-- accordion -->
                            <div id="accordion">
                            
                                <div class="card">
                                        <div class="card-header">
                                            <ul class="menu-category" style="list-style-type: none">
                                                @foreach($categories as $category)
                                                    <li class="has-submenu">
                                                    <a href="{{route('products.index', ['category_id' => $category->id])}}" style="line-height: 27px;"><span>{{$category->name}}<i
                                                                class="pe-7s-angle-right"></span></i></a>
                                    
                                                                @php
                                                                    $children = TCG\Voyager\Models\Category::where('parent_id', $category->id)->get();
                                                                @endphp
                                    
                                                           @if($children->isNotEmpty())
                                                            <div class="category-menu-dropdown">
                                    
                                                                @foreach ($children as $child)
                                                                    <div class="category-dropdown-style category-common3">
                                                                        <div class="submenu" style="display: none;">
                                                                            <a href="{{route('products.index', ['category_id' => $child->id])}}">
                                                                            {{$child->name}}
                                                                            </a>
                                                                        </div>
                                                                        @php
                                                                            $grandChild = TCG\Voyager\Models\Category::where('parent_id', $child->id)->get();
                                                                        @endphp
                                                                        @if($grandChild->isNotEmpty())
                                                                            <ul class="submenu" style="list-style-type: none; display:none;">
                                                                                @foreach ($grandChild as $c)
                                                                                    <li class="has-submenu"><a href="{{route('products.index', ['category_id' => $c->id])}}">{{$c->name}}</a></li>
                                                                                @endforeach
                                                                            </ul>
                                                                        @endif
                                                                    </div>
                                                                @endforeach
                                    
                                    
                                                            </div>
                                    
                                                          @endif
                                                    </li>
                                    
                                                @endforeach
                                    
                                            </ul> 
                                    
                                            

                                        </div>
                         
                                </div>
                                <div class="card" style="display: none">
                                    <div class="card-header">
                                        <a href="" data-toggle="collapse" data-target="#collapse3">
                                            <span>Home Appliance</span>
                                            <i class="fa fa-angle-down"></i>
                                        </a>
                                    </div>
                                    <div id="collapse3" class="collapse">
                                        <div class="card-body">
                                            <ul class="list-unstyled">
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 1</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 2</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 3</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 4</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="card" style="display: none">
                                    <div class="card-header">
                                        <a href="" data-toggle="collapse" data-target="#collapse4">
                                            <span>Smartphone</span>
                                            <i class="fa fa-angle-down"></i>
                                        </a>
                                    </div>
                                    <div id="collapse4" class="collapse">
                                        <div class="card-body">
                                            <ul class="list-unstyled">
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 1</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 2</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 3</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 4</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="card" style="display: none">
                                    <div class="card-header">
                                        <a href="" data-toggle="collapse" data-target="#collapse5">
                                            <span>Computer</span>
                                            <i class="fa fa-angle-down"></i>
                                        </a>
                                    </div>
                                    <div id="collapse5" class="collapse">
                                        <div class="card-body">
                                            <ul class="list-unstyled">
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 1</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 2</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 3</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 4</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="card" style="display: none">
                                    <div class="card-header">
                                        <a href="" data-toggle="collapse" data-target="#collapse6">
                                            <span>Kids Collection</span>
                                            <i class="fa fa-angle-down"></i>
                                        </a>
                                    </div>
                                    <div id="collapse6" class="collapse">
                                        <div class="card-body">
                                            <ul class="list-unstyled">
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 1</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 2</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 3</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 4</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <div class="card" style="display: none">
                                    <div class="card-header">
                                        <a href="" data-toggle="collapse" data-target="#collapse7">
                                            <span>Automobile</span>
                                            <i class="fa fa-angle-down"></i>
                                        </a>
                                    </div>
                                    <div id="collapse7" class="collapse">
                                        <div class="card-body">
                                            <ul class="list-unstyled">
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 1</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 2</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 3</a></li>
                                                <li><a href=""><i class="fa fa-angle-right"></i> Catagory 4</a></li>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="cat-brand">
                            <div class="sec-title">
                                <h6>Brands</h6>
                            </div>
                           
                            
                            
                            <div class="brand-box">
                                <?php use App\Product; ?>
                               <?php $brands = Product::select('brand')->groupBy('brand')->get(); ?>

                                
                                @foreach ($brands as $brand )

                                    <ul class="list-unstyled">   
                                        <li><input  id="brand" class="try" value="{{ $brand->brand}}"  class="try" type="checkbox">&nbsp;&nbsp;<span>{{ ucwords($brand->brand) }}</span>({{App\Product::where('brand',$brand->brand)->count()}})</li>  
                                    </ul>

                                @endforeach
                                
                            </div>
                                

                            
                        </div>
                        <div class="price-range">
                            <div class="sec-title">
                                <h6>Price</h6>
                            </div>
                            <div class="price-filter">
                                <div>
                                    <div id="slider-range"></div>
                                    <b><input size="2" type="text" id="amount_start" name="start_price" value="15" readonly="readonly"></b>
                                    <b><input size="2" type="text" id="amount_end" name="end_price" value="65" readonly="readonly"></b>  
                                   <!-- <button type="button" name="button">Filter</button>-->
                                    <button onclick="send()">Filter</button>
                                </div>
						    </div>
                        </div>



                        <div class="color">
                            <div class="sec-title">
                                <h6>Color</h6>
                            </div>
                            <ul class="list-unstyled color-box">
                                <li><input type="checkbox" id="red" name="name"><label for="red"><span style="background: red;"></span>Red</label></li>
                                <li><input type="checkbox" id="green" name="name"><label for="green"><span style="background: green;"></span>Green</label></li>
                                <li><input type="checkbox" id="blue" name="name"><label for="blue"><span style="background: blue;"></span>Blue</label></li>
                                <li><input type="checkbox" id="gold" name="name"><label for="gold"><span style="background: gold;"></span>Golden</label></li>
                                <li><input type="checkbox" id="brown" name="name"><label for="brown"><span style="background: brown;"></span>Brown</label></li>
                                <li><input type="checkbox" id="black" name="name"><label for="black"><span style="background: black;"></span>Black</label></li>
                            </ul>
                        </div>
                        <div class="pro-tag">
                            <div class="sec-title">
                                <h6>Product Tag</h6>
                            </div>
                            <div class="tag-box">
                                <a href="">Shirt</a>
                                <a href="">Smartphone</a>
                                <a href="">Camera</a>
                                <a href="">Pant</a>
                                <a href="">Glass</a>
                                <a href="">Smart Led Tv</a>
                                <a href="">Watch</a>
                                <a href="">Micro Oven</a>
                                <a href="">Toy</a>
                            </div>
                        </div>
                        <div class="add-box">
                            <a href=""><img src="images/s-banner2.jpg" alt="" class="img-fluid"></a>
                        </div>
                    </div>
                    <div class="col-md-9" id="updateDiv">
                        <div  class="product-box">
                            <div class="cat-box d-flex justify-content-between">
                                <!-- Nav tabs -->
                                <div class="view">
                                    <ul class="nav nav-tabs" role="tablist">
                                        <li class="nav-item">
                                            <a class="nav-link active" data-toggle="tab" href="#grid"><i class="fa fa-th-large"></i></a>
                                        </li>
                                        <li class="nav-item">
                                            <a class="nav-link" data-toggle="tab" href="#list"><i class="fa fa-th-list"></i></a>
                                        </li>
                                    </ul>
                                </div>
                              
                                
                                
                            </div>

                            <!-- Tab panes -->
                            <div class="tab-content">
                                <div class="tab-pane fade show active" id="grid" role="tabpanel">
                                    <div class="row">
                                        @foreach ($allProducts as $product)
                                        <div class="col-lg-4 col-md-6">
                                            <div class="tab-item">
                                                <div class="tab-img">
                                                    
                                                    <img class="main-img img-fluid" src="{{asset('storage/'.$product->cover_img)}}" alt="">
                                                    <img class="sec-img img-fluid" src="{{asset('storage/'.$product->cover_img)}}" alt="">
                                                    <div class="layer-box">
                                                     
                                                        <a href="" class="it-comp" data-toggle="tooltip" data-placement="left" title="Compare"><img src="{{ asset('images/it-comp.png') }}" alt=""></a>
                                                        <a href="" class="it-fav" data-toggle="tooltip" data-placement="left" title="Favourite"><img src="{{ asset('images/it-fav.png') }}" alt=""></a>
                                                    </div>
                                                </div>
                                                <div class="tab-heading">
                                                    <p><a href="{{url('product/'.$product->id)}}">{{$product->name}}</a></p>
                                                </div>
                                                <div class="img-content d-flex justify-content-between">
                                                    <div>
                                                        <ul class="list-unstyled list-inline fav">
                                                            <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                            <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                            <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                            <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                            <li class="list-inline-item"><i class="fa fa-star-o"></i></li>
                                                        </ul>
                                                        <ul class="list-unstyled list-inline ">
                                                            <li class="list-inline-item" style="font-size: 16px"><b>KES {{$product->price}}</b></li>
                                                            
                                                        </ul>
                                                    </div>
                                                    <div>
                                                        <a href="{{route('cart.add', $product->id)}}" data-toggle="tooltip" data-placement="top" title="Add to Cart"><img src="{{ asset('images/it-cart.png') }}" alt=""></a>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        @endforeach

                                    </div>
                                </div>
                                <div class="tab-pane fade" id="list" role="tabpanel">
                                    <div class="row">

                                        @foreach ($allProducts as $product)
                                        <div class="col-lg-12 col-md-6">
                                            <div class="tab-item2">
                                                <div class="row">
                                                    <div class="col-lg-4 col-md-12">
                                                        <div class="tab-img">
                                                            <img class="main-img img-fluid" src="{{asset('storage/'.$product->cover_img)}}" alt="">
                                                            <img class="sec-img img-fluid" src="{{asset('storage/'.$product->cover_img)}}" alt="">
                                                            
                                                        </div>
                                                    </div>
                                                    <div class="col-lg-8 col-md-12">
                                                        <div class="item-heading d-flex justify-content-between">
                                                            <div class="item-top">
                                                                <ul class="list-unstyled list-inline cate">
                                                                    <li class="list-inline-item"><p>{{$product->name}}</p></li>
                                                                    
                                                                </ul>
                                                                <p><a href="{{url('product/'.$product->id)}}">{{$product->details}}</a></p>
                                                                <ul class="list-unstyled list-inline fav">
                                                                    <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                                    <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                                    <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                                    <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                                                    <li class="list-inline-item"><i class="fa fa-star-o"></i></li>
                                                                </ul>
                                                            </div>
                                                            <div class="item-price">
                                                                <ul class="list-unstyled list-inline">
                                                                    <li class="list-inline-item" style="font-size: 16px"><b>KES {{$product->price}}</b></li>  
                                                                </ul>
                                                            </div>
                                                        </div>
                                                        <div class="item-content">
                                                            <p></p>
                                                            <a href="{{route('cart.add', $product->id)}}" data-toggle="tooltip" data-placement="top" title="Add to Cart"><img src="{{ asset('images/it-cart.png') }}" alt=""></a>
                                                            <a href="" class="it-fav" data-toggle="tooltip" data-placement="top" title="Favourite"><img src="{{ asset('images/it-fav.png') }}" alt=""></a>
                                                            <a href="" class="it-comp" data-toggle="tooltip" data-placement="top" title="Compare"><img src="{{ asset('images/it-comp.png') }}" alt=""></a>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        @endforeach


                                    </div>
                                </div>
                            </div>

                            <div style="position: relative; left:320px;">
                                {{ $allProducts->links() }}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- End Category Area -->



        <!-- Brand area 2 -->
        <section class="brand2">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <div class="tp-bnd owl-carousel">
                            <div class="bnd-items">
                                <a href="#"><img src="{{ asset('images/brand-01.png') }}" alt="" class="img-fluid"></a>
                            </div>
                            <div class="bnd-items">
                                <a href="#"><img src="{{ asset('images/brand-02.png') }}" alt="" class="img-fluid"></a>
                            </div>
                            <div class="bnd-items">
                                <a href="#"><img src="{{ asset('images/brand-03.png') }}" alt="" class="img-fluid"></a>
                            </div>
                            <div class="bnd-items">
                                <a href="#"><img src="{{ asset('images/brand-04.png') }}" alt="" class="img-fluid"></a>
                            </div>
                            <div class="bnd-items">
                                <a href="#"><img src="{{ asset('images/brand-05.png') }}" alt="" class="img-fluid"></a>
                            </div>
                            <div class="bnd-items">
                                <a href="#"><img src="{{ asset('images/brand-06.png') }}" alt="" class="img-fluid"></a>
                            </div>
                            <div class="bnd-items">
                                <a href="#"><img src="{{ asset('images/brand-07.png') }}" alt="" class="img-fluid"></a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- End Brand area 2 -->

@endsection
May
31
2 months ago
Activity icon

Started a new Conversation Display Products Within An Order After Emptying Cart

I have two tables, products and order items. I would like to generate a printable pdf of products within the order after I have emptied the cart. How do i do that? I have used a laravel shopping cart package by darryldecode and after emptying cart i have a hard time getting products in order.

Heres my tables: Order Items table


        Schema::create('order_items', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('order_id');
            $table->unsignedBigInteger('product_id');

            $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
            $table->foreign('order_id')->references('id')->on('orders')->onDelete('cascade');

            $table->float('price');
            $table->integer('quantity');

            $table->timestamps();

Products table:

Schema::create('products', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('details');
            $table->string('description')->nullable();
            $table->string('brand')->nullable();
            $table->enum('is_available', ['Available', 'Out of Stock'])->default('Available');
            $table->float('price');
            $table->string('cover_img')->nullable();
            $table->string('alt_img')->nullable();
            $table->string('alt_img2')->nullable();
            $table->string('alt_img3')->nullable();
            $table->unsignedBigInteger('shop_id')->nullable();
            $table->foreign('shop_id')->references('id')->on('shops')->onDelete('cascade');
            $table->timestamps();
May
27
2 months ago
Activity icon

Replied to How Do I Fetch An External Php Class To Javascript

External PHP Class:

<?php
namespace App\Classes;

class EncryptParameters{
    /**
    * Merchant's IV key
    */
   private $iv;
   /**
    * Merchant's secret key
    */
   private $key;
   /**
    * EncryptParameters constructor.
    */
   public function __construct()
   {
       $this->iv = '2BfjH469WxmcJdPM';
       $this->key = 'QpJXdbYv6tHLhCTK';
//       $this->request = !empty($_POST)? $_POST:json_decode(file_get_contents('php://input'), true);
   }
   /**
    * Encrypt the string of customer details with the IV and secret key.
    *
    * @param $payload Pass in the array of parameters to be pass to express checkout.
    * @return string
    */
   public function encryptData($payload = [])
   {
        //The encryption method to be used
        $encrypt_method = "AES-256-CBC";
        // Hash the secret key
        $key = hash('sha256', $this->key);
        // Hash the iv - encrypt method AES-256-CBC expects 16 bytes
        $iv = substr(hash('sha256', $this->iv), 0, 16);
        $encrypted = openssl_encrypt(
            json_encode($payload, true),
            $encrypt_method,
            $key,
            0,
            $iv
        );
        //Base 64 Encode the encrypted payload
        $encrypted = base64_encode($encrypted);

        //echo json_encode($iv);

        $result = array(
            'params' => $encrypted,
            'accessKey' => $payload['a$I.qb6TCaxdv5stvnZuvWGuRrTOvflWUo.EtSxFOmnLXd5P1Yegwim'],
            'countryCode' => $payload['KE']
        );

        echo json_encode($result);
    }
}

$class = new EncryptParameters;
$request = !empty($_POST)? $_POST:json_decode(file_get_contents('php://input'), true);

$class->encryptData($request);
Activity icon

Started a new Conversation How Do I Fetch An External Php Class To Javascript

I have some javascript code within my view in laraveland i am trying to fetch an external php class which creates an encryption endpoint then executes the Javascript. How do I do this in Laravel, how do i call a URL of the class?

<!-- Include the mula Express checkout library -->
<!-- Initialize the "Pay with mula" button -->
<script type="text/javascript">
// End point to your service that handles encryption
const merchantURL = " **THE PHP CLASS URL COME IN HERE**";

</script>
May
25
2 months ago
Activity icon

Started a new Conversation I Need Help Using Kenyan Payment Gateway

I am trying to integrate a Kenyan Payment Gateway, Tingg, to my laravel project but i am having some challenges. Being a newbie to Laravel and Php, I am having a hard time changing their code which is written in Php to Laravel. There is an encryption endpoint php class that seems to give errors everytime i click on a button link to redirect me to an express checkout page. Help me recreate the php code to laravel. All the help with this will be sincerely appreciated.

The Php Class:

<?php
class EncryptParameters{
    /**
    * Merchant's IV key
    */
   private $iv;
   /**
    * Merchant's secret key
    */
   private $key;
   /**
    * EncryptParameters constructor.
    */
   public function __construct()
   {
       $this->iv = 'QnP4mk3WDy8VFzKw';
       $this->key = 'KmQkqYrZ389D2zRJ';
//       $this->request = !empty($_POST)? $_POST:json_decode(file_get_contents('php://input'), true);
   }
   /**
    * Encrypt the string of customer details with the IV and secret key.
    *
    * @param $payload Pass in the array of parameters to be pass to express checkout.
    * @return string
    */
   public function encryptData($payload = [])
   {
        //The encryption method to be used
        $encrypt_method = "AES-256-CBC";
        // Hash the secret key
        $key = hash('sha256', $this->key);
        // Hash the iv - encrypt method AES-256-CBC expects 16 bytes
        $iv = substr(hash('sha256', $this->iv), 0, 16);
        $encrypted = openssl_encrypt(
            json_encode($payload, true),
            $encrypt_method,
            $key,
            0,
            $iv
        );
        //Base 64 Encode the encrypted payload
        $encrypted = base64_encode($encrypted);

        $result = array(
            'params' => $encrypted,
            'accessKey' => $payload['accessKey'],
            'countryCode' => $payload['countryCode']
        );

        echo json_encode($result);
    }
}

$class = new EncryptParameters;
$request = !empty($_POST)? $_POST:json_decode(file_get_contents('php://input'), true);

$class->encryptData($request);


The Javascript Code with Button:

<!-- The "Pay with mula" button needs to have the "mula-checkout-button" class -->
<a class="checkout-button"></a>

<!-- Include a polyfil for to support the old browsers -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/1.0.17/webcomponents-loader.js"></script>

<!-- Include the mula Express checkout library -->
<script id="mula-checkout-library" type="text/javascript" src="https://beep2.cellulant.com:9212/checkout/v2/tingg-checkout.js" charset="utf-8"></script>

<!-- Include the mula Express checkout library -->
<!-- Initialize the "Pay with mula" button -->
<script type="text/javascript">
    // End point to your service that handles encryption
    const merchantURL = "http://localhost/checkout/encrypt.php";

    const no = Math.floor((Math.random() * 50000000) + 10000000);

    const params = {
        merchantTransactionID: no,
        customerFirstName: 'TestName',
        customerLastName: "TestName",
        customerEmail: "[email protected]",
        amount: 12,
        accountNumber: no,
        currencyCode: 'KES',
        languageCode: 'en',
        serviceDescription: 'Payment for the AfterWork Data Science Program',
        transactionID: no,
        serviceCode: '',
        productCode: '',
        payerClientCode:"",
        MSISDN: '',
        countryCode: '',
        accessKey:"", // Input your access key here
        dueDate: '2020-05-22 19:30:005',
        successRedirectUrl:"http://127.0.0.1:8000/payment-success",
        failRedirectUrl: "http://127.0.0.1:8000/payment-failed",
        paymentWebhookUrl: "http://127.0.0.1:8000/webhook"
    }; // The params to be encrypted

    Tingg.renderPayButton({ className:'checkout-button', checkoutType:'redirect'});

    // Initialize the mula checkout modal/redirect
    //on button click, redirect to express checkout
    document.querySelector(".checkout-button").addEventListener("click", function () {

        function encrypt() {
            var request = new XMLHttpRequest();
            request.open('POST', merchantURL, true);
            request.setRequestHeader('Content-Type',
                'application/json; charset=UTF-8',
                'Access-Control-Allow-Origin', '*',
            );

            request.onreadystatechange = function() {

                if(this.readyState == XMLHttpRequest.DONE && this.status == 200) {
                    var jsonData = JSON.parse(request.responseText);

                    Tingg.renderCheckout({
                        checkoutType: "redirect",
                        merchantProperties: jsonData
                    });
                }
            }

            request.send(JSON.stringify(params));
        }
        //encrypt and load checkout
        encrypt();
    });
</script>
Activity icon

Replied to How Can I Fetch A Php Class To A Laravel Project

@cronix so where does the php class come in, in the controller?

Activity icon

Replied to How Can I Fetch A Php Class To A Laravel Project

Okay, its a Kenyan payment gateway, Tingg

Activity icon

Replied to How Can I Fetch A Php Class To A Laravel Project

Thanks @jlrdw for the response. Honestly, i am implementing a payment gateway. However, the docs for the gateway are not informative. Also, i have tried the laravel docs and i seem not to be finding the answers i am looking for. Hence, if you won't mind, i just needed to know, how is the class implemented, do i have to create an api with a controller and model, and so on, or what is the actually procedure of doing this?

Activity icon

Started a new Conversation How Can I Fetch A Php Class To A Laravel Project

I am new to php and laravel I need to fetch a php class endpoint and insert into the javascript section of my php project, how is this achieved, what is the procedure? All the help will be higly appreciated.

My javascript:

document
.querySelector('.awesome-checkout-button')
.addEventListener('click', function() {
 //create the checkout request

	fetch('<THE URL IS INSERTED HERE >', {
   
 method: 'post',
    headers: {
        'Content-type': 'application/json; charset=UTF-8'
    },
    //checkout details as shown above
    body: payload
	 })

This is my php endpoint code:

<?php
class Checkout {
private $secret;
private $IV;

public function __construct($secret, $IV) {
    $this->secret = $secret;
    $this->IV = $IV;
}

public function encrypt($requestBody) {
    $secret = hash('sha256', $this->secret);
    $IV = substr(hash('sha256', $this->IV), 0, 16);

    $payload = json_encode($requestBody);
    $result = openssl_encrypt(
        $payload, 
        'AES-256-CBC', 
        $secret, 
        0, 
        $IV
    );

    return base64_encode($result);
 }
}

// Get the body of the post request made 
// after the customer clicked the checkout button
$checkoutRequestBody = file_get_contents('php://input');

// The Request body is read into a string,
// so we decode the JSON string into a PHP associative array
$checkoutPayload = json_decode($checkoutRequestBody);

$checkout = new Checkout(
	'6PZ7pTGbMHyRK8XN',
	'3MY6hpwJQy9b7cfn'
);
$params = $checkout->encrypt($checkoutPayload);
header('Content-Type: application/json');
echo json_encode(array("params" => $params));
?>
May
18
2 months ago
Activity icon

Replied to Undefined Index: Url

@michaloravec, thanks for the response. I tried it and it gets rid of the error and in its place, I get a blank page, that is when I insert a default route

Activity icon

Replied to Undefined Index: Url

@michaloravec, Kindly explain to me what you mean by this, You don't send url to public function filter(Request $request) in:

  $finalUrl = "products/" . $data['url'] . "?" . $colorUrl;
Activity icon

Replied to Undefined Index: Url

The view...

	<div class="cat-brand">
                        <div class="sec-title">
                            <h6>Brands</h6>
                        </div>
                        <form action="{{ url('/products/filter')}}" method="POST">
                        @if(!empty($url))
                            <input name="url" value="{{ $url }}" type="hidden">
                        @endif 
                        @csrf
                        <div class="brand-box">
                            

                            @foreach($brandArray as $brand)
                                @if(!empty($_GET['brand']))
                                <?php $brandrArr = explode('-',$_GET['brand']) ?>
                                @if(in_array($brand,$brandArr))
                                    <?php $brandcheck="checked"; ?>	
                                @else
                                    <?php $brandcheck=""; ?>
                                @endif		
                                @else
                                    <?php $brandcheck=""; ?>
                                @endif

                                <ul class="list-unstyled">
                                    <li><input name="brandFilter[]" onchange="javascript:this.form.submit();" id="{{ $brand 
                                 }}" value="{{ $brand }}" type="checkbox" {{ $brandcheck }}>&nbsp;&nbsp;<span>{{ 
                                  $brand }}</span>          
                                 </li>
                                   
                                </ul>

                            @endforeach

                        </div>
                        </form>
                    </div>
Activity icon

Replied to Undefined Index: Url

@wingly already dealt with that

Activity icon

Replied to Undefined Index: Url

The focus of the error occurs in the filter method when assigning values to $finalUrl variable

Activity icon

Replied to Undefined Index: Url

@michaloravec , still getting the same error

Activity icon

Started a new Conversation Undefined Index: Url

How do I initialize URL variable? I am implementing a brand filter for my e-commerce and i get this error when trying to load a filter.

These are my controller functions:

    public function allproducts(Request $request, $url)
{
    $products = Product::take(50)->paginate(15);
    $categories = Category::whereNull('parent_id')->get(); //where(['url'=>$url,'parent_id'])

    if (!empty($_GET['brand'])) {
        $brandArray = explode('-', $_GET['brand']);
        $products = $products->whereIn('products.product_brand', $brandArray);
    }
    $brandArray = Product::select('brand')->groupBy('brand')->get();
    //$coArray = array_flatten(json_decode(json_encode($colorArray),true));

    return view('product.all')->with(compact(['allProducts' => $products, 'categories' => $categories, 'url' 
    =>  $url, 'brandArray' => $brandArray]));

}


public function filter(Request $request)
{

    $data = $request->all();
    /*echo "<pre>";
    print_r($data);*/

    $brandUrl = "";
    if (!empty($data['brandFilter'])) {
        foreach ($data['brandFilter'] as $brand) {
            if (empty($brandUrl)) {
                $brandUrl = "&brand=" . $brand;
            } else {
                $brandUrl .= "-" . $brand;
            }
        }
    }
    $finalUrl = "products/" . $data['url'] . "?" . $colorUrl;
    return redirect::to($finalUrl);
}
May
15
2 months ago
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

Sorry about that. However, I got to understand what I was doing wrong so thanks a lot.

Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

This has actually done the trick :-)

 $productDetails = Product::with('reviews')->find($request->product_id);

I am sincerely very grateful for all your input. @michaloravec

Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

Ok, now i get you. So heres the result:

 App\Product {#879 ▼
 #connection: "mysql"
 #table: "products"
 #primaryKey: "id"
 #keyType: "int"
+incrementing: true
 #with: []
 #withCount: []
 #perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:14 [▼
"id" => 13
"name" => "Power Grinder"
"details" => "Bosch Brand New Grinder"
"description" => "The Bosch 1375A 4-1/2 In. Angle Grinder features a powerful 
 6.0 Amp motor that produces 
11,000 no-load RPM, making this compact grinder a powerhouse tool."
"brand" => "Bosch"
"is_available" => "Available"
"price" => 7500.0
"cover_img" => "products\May2020\mCc1DdkJ4T5vpOuIn9Bl.jpg"
"alt_img" => "products\May2020\XLtcc2LcAndYy1N8M8I6.jpg"
"alt_img2" => "products\May2020\WDEMig3lm40jPGjgOaaG.jpg"
"alt_img3" => "products\May2020\ZlDbdRNw6FQY984mrZzT.jpg"
"shop_id" => 21
"created_at" => "2020-05-09 13:03:00"
"updated_at" => "2020-05-11 13:08:50"
 ]
 #original: array:14 [▼
"id" => 13
"name" => "Power Grinder"
"details" => "Bosch Brand New Grinder"
"description" => "The Bosch 1375A 4-1/2 In. Angle Grinder features a powerful 6.0 Amp motor that produces 11,000 no-load RPM, making this compact grinder a powerhouse tool."
"brand" => "Bosch"
"is_available" => "Available"
"price" => 7500.0
"cover_img" => "products\May2020\mCc1DdkJ4T5vpOuIn9Bl.jpg"
"alt_img" => "products\May2020\XLtcc2LcAndYy1N8M8I6.jpg"
"alt_img2" => "products\May2020\WDEMig3lm40jPGjgOaaG.jpg"
"alt_img3" => "products\May2020\ZlDbdRNw6FQY984mrZzT.jpg"
"shop_id" => 21
"created_at" => "2020-05-09 13:03:00"
"updated_at" => "2020-05-11 13:08:50"
 ]
 #changes: []
 #casts: []
  #classCastCache: []
  #dates: []
  #dateFormat: null
  #appends: []
   #dispatchesEvents: []
  #observables: []
   #relations: array:1 [▶]
   #touches: []
   +timestamps: true
  #hidden: []
   #visible: []
   #fillable: []
    #guarded: array:1 [▼
  0 => "*"
 ]
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

Honestly, i have no controller where i have created a variable $productDetails in relation to reviews.

Should i have this $productDetails in ProductController or any controller by any chance?

Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

Here are the models:

User Model:

class Product extends Model
{
public function shop()
{
    return $this->belongsTo('App\Shop', 'shop_id');
}

public function reviews()
{
    return $this->hasMany(ProductReview::class);
}

}

ProductReviews Model:

class ProductReview extends Model
{
protected $fillable = [
    'headline', 'description', 'rating', 'product_id',
];
}

Product Model:

class Product extends Model
{
public function shop()
{
    return $this->belongsTo('App\Shop', 'shop_id');
}

public function reviews()
{
    return $this->hasMany(ProductReview::class);
}

}
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

I am still getting this as the error:

Undefined property: stdClass::$reviews
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

I don't know what am doing wrong, still no breakthroughs.

Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

Kindly explain to me what you are doing here:

$productDetails = Product::with('reviews')->find($request->product_id);
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

@michaloravec, yes it does. Heres, the relationship:

 public function reviews()
{
    return $this->hasMany(ProductReview::class);
}
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

Actually, the getStarRating() is non functional in the code so i removed it and the error cleared out.

So now i get this new error:

Undefined property: stdClass::$reviews

my reviews controller is:

public function store(Request $request)
{
    auth()->user()->review()->create($request->all());

}

with the blade having:

              <ul>
                 @forelse ($productDetails->reviews as $review)

                  <li>{{$review->headline}}</li>
                                                        
                 @empty
                                                        
                 @endforelse
                  </ul>
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

Heres my result for the dump and die:

Illuminate\Support\Collection {#893 ▼
   #items: array:1 [▼
  0 => {#888 ▼
  +"id": 13
  +"name": "Power Grinder"
  +"details": "Bosch Brand New Grinder"
  +"description": "The Bosch 1375A 4-1/2 In. Angle Grinder features a powerful 6.0 Amp motor that produces 			 
  11,000 no-load RPM, making this compact grinder a powerhouse tool."
  +"brand": "Bosch"
  +"is_available": "Available"
  +"price": 7500.0
  +"cover_img": "products\May2020\mCc1DdkJ4T5vpOuIn9Bl.jpg"
  +"alt_img": "products\May2020\XLtcc2LcAndYy1N8M8I6.jpg"
  +"alt_img2": "products\May2020\WDEMig3lm40jPGjgOaaG.jpg"
  +"alt_img3": "products\May2020\ZlDbdRNw6FQY984mrZzT.jpg"
  +"shop_id": 21
  +"created_at": "2020-05-09 13:03:00"
  +"updated_at": "2020-05-11 13:08:50"
}

] }

For the blade file:

                            <div class="tab-pane" id="sg2" role="tabpanel">
                                <img src="{{asset('storage/'.$productDetails->alt_img)}}" alt="" class="img-fluid">
                            </div>
                           
                            <div class="tab-pane" id="sg3" role="tabpanel">
                                <img src="{{asset('storage/'.$productDetails->alt_img2)}}" alt="" class="img-fluid">
                            </div>
                            <div class="tab-pane" id="sg4" role="tabpanel">
                                <img src="{{asset('storage/'.$productDetails->alt_img3)}}" alt="" class="img-fluid">
                            </div>
                        </div>
                        <div class="nav d-flex justify-content-between">
                            <a class="nav-item nav-link active" data-toggle="tab" href="#sg1"><img src="{{asset('storage/'.$productDetails->cover_img)}}" alt=""></a>
                            <a class="nav-item nav-link" data-toggle="tab" href="#sg2"><img src="{{asset('storage/'.$productDetails->alt_img)}}" alt=""></a>
                            <a class="nav-item nav-link" data-toggle="tab" href="#sg3"><img src="{{asset('storage/'.$productDetails->alt_img2)}}" alt=""></a>
                            <a class="nav-item nav-link" data-toggle="tab" href="#sg4"><img src="{{asset('storage/'.$productDetails->alt_img3)}}" alt=""></a>
                        </div>
                    </div>
                </div>
                <div class="col-md-6 ml-10">
                    <div class="sg-content">
                        <div class="pro-tag">
                            <ul class="list-unstyled list-inline">
                               <!-- <li class="list-inline-item"><a href="">Home Appliance ,</a></li>
                                <li class="list-inline-item"><a href="">Smart Led Tv</a></li> -->
                            </ul>
                        </div>
                         <div class="pro-name">
                             <p>{{$productDetails->name}}</p>
                         </div>
                         <div class="pro-rating">
                             <ul class="list-unstyled list-inline">
                                 <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                 <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                 <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                 <li class="list-inline-item"><i class="fa fa-star"></i></li>
                                 <li class="list-inline-item"><i class="fa fa-star-o"></i></li>
                                 <li class="list-inline-item"><a href="">( Review )</a></li>
                             </ul>
                         </div>
                         <div class="pro-price">
                             <ul class=" list-inline">
                                 <li class="list-inline-item">KES {{$productDetails->price}}</li>
                                 <li class="list-inline-item" style="display: none">KES {{$productDetails->price}}</li>
        
                             </ul>
                             <p>Availability : <span>{{$productDetails->is_available}}</span> </p>
                         </div>
                         <div class="colo-siz">
                             
                             
                             
                             <div class="pro-btns">
                                  <a href="{{route('cart.add', $productDetails->id)}}" class="cart" id="CartButton" name="CartButton">Add To Cart</a>
                                  
                                  <br><br>
                                 
                                  <?php
                                  $wishlistData=DB::table('wish_list')->rightJoin('products','wish_list.product_id','=','products.id')
                                  ->where('wish_list.product_id','=',$productDetails->id)->get();
                                  $count=App\Wishlist::where(['product_id'=>$productDetails->id])->count();
                                  if($count=="0"){
                              ?>
                              <form action="{{route('addToWishList')}}" method="post" role="form">
                                  <input type="hidden" name="_token" value="{{csrf_token()}}">
                                  <input type="hidden" value="{{$productDetails->id}}" name="product_id">
                                  <button type="submit" class="btn btn-default">Add to Wishlist</button>
                              </form>
                              <?php }else{?>
                                  <h3 style="color:green">Added to Wishlist</h3><a href="{{url('/WishList')}}" class="fav-com ml-2" data-toggle="tooltip" data-placement="top" title="View Your Wishlist"><img src="{{ asset('images/it-fav.png') }}" alt=""></a>
                              <?php }?>








    









                                 


                                  
                                  <a href="" class="fav-com"  data-toggle="tooltip" data-placement="top" title="Compare"><img src="{{ asset('images/it-comp.png') }}" alt=""></a>
                                  <button class="btn btn-primary py-2 ml-1" style="border-radius: 17px"    onclick="window.location.href = '{{url('quote/'.$productDetails->id)}}';">Request for Quote</button>
                             </div>
                             
                         </div>
                    </div>
                </div>
                <div class="col-md-12">
                    <div class="sg-tab">
                        <ul class="nav nav-tabs" role="tablist">
                            <li class="nav-item"><a class="nav-link active" data-toggle="tab" href="#pro-det">Product Details</a></li>
                            <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#company">Company Profile</a></li>

                            <li class="nav-item"><a class="nav-link" data-toggle="tab" href="#rev">Reviews</a></li>
                        </ul>
                        <div class="tab-content">
                            <div class="tab-pane fade show active" id="pro-det" role="tabpanel">
                                <p>{{$productDetails->description}}</p>
                            </div>

                            <div class="tab-pane fade" id="company" role="tabpanel">
                                <p>{{$productDetails->description}}</p>
                            </div>


                            <div class="tab-pane fade" id="rev" role="tabpanel">
                                
                                <div class="review-form">
                                    <h6>Add Your Review</h6>
                                <form action="{{route('review.store')}}" method="POST">
                                    @csrf
                                        <div class="row">
                                            <div class="col-md-12">
                                                <div class="star-rating">
                                                    <label>Your Rating*</label>                                                       
                                                    <input type="text" name="rating" class="rating-value">
                                                </div>
                                            </div>
                                            <div class="col-md-6">
                                                <label for="headline">Headline</label>

                                                


                                                <star-rating :rating="{{$productDetails->getStarRating()}}"></star-rating>

                                                <input type="text" name="headline">
                                            </div>
                                            <div class="col-md-6">
                                            <input type="hidden" name="product_id" value="{{$productDetails->id}}">
                                            </div>

                                            <div class="col-md-12">
                                                <label>Your Review*</label>
                                                <textarea required="" name="description"></textarea>
                                                <button type="submit">Add Review</button>
                                            </div>
                                            <div class="col-md-6">
                                                <h4 class="py-5"><u>Reviews</u></h4>
                                                <ul>
                                                    @forelse ($productDetails->reviews as $review)

                                                <li>{{$review->headline}}</li>
                                                        
                                                    @empty
                                                        
                                                    @endforelse
                                                </ul>

                                            </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                
            </div>
        </div>
Activity icon

Replied to Property [cover_img] Does Not Exist On This Collection Instance

It's part of the blade file posted earlier but I excepted it at first.