nicwek

nicwek

Member Since 2 Weeks Ago

Experience Points
700
Total
Experience

4,300 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
700 XP
May
31
2 days 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
6 days 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
1 week 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 weeks 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 weeks 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.

Activity icon

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

Thanks, @michaloravec, for the quick response. However, I just tried to implement it your way and am getting additional errors and this time, no item is being added to the wishlist.

Call to undefined method stdClass::getStarRating()
Activity icon

Started a new Conversation Property [cover_img] Does Not Exist On This Collection Instance

I am implementing a wish list for an ecommerce platform and i keep on getting this error, although everything works out pretty fine. How can i get rid of the error? Any input will be highly appreciated. Here's my code:

//My controller function for add to wishlist
public function addWishList(Request $request)
{
    $wishlist = new Wishlist();

    $wishlist->user_id = Auth::user()->id;
    $wishlist->product_id = $request->product_id;
    $wishlist->save();

    $productDetails = DB::table('products')->where('id', $request->product_id)->get();
    return view('product.detail', compact('productDetails'));

}

Here's part my view code:

			<div class="tab-pane fade show active easyzoom easyzoom--overlay 
			easyzoom--with-thumbnails" i
			d="sg1" role="tabpanel">
                                <a href="{{asset('storage/'.$productDetails->cover_img)}}">
                                    <img src="{{asset('storage/'.$productDetails->cover_img)}}" 
			style="width: 300px;"   alt="" class="img-fluid">
                                </a>
                            </div>

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

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

                                   <img src="{{ asset('images/it-fav.png') }}" alt=""></a>
                                  <?php }?>
May
13
2 weeks ago
Activity icon

Replied to Send Dymamic Email With Generated PDF

Thanks alot @snapey , i tried your solution and it worked.

May
12
3 weeks ago
Activity icon

Started a new Conversation Send Dymamic Email With Generated PDF

I am trying to creating an e-commerce platform where an auto-generated pdf of clients' orders is sent to their emails as an attachment. I have been through several forums and I see most people are hardcoding the user email address which is not my intention. Kindly assist.

In my OrderController:

$pdf = \PDF::loadview('OrderPDF');
    $try = $pdf->output();

    Mail::to($request->user())->send(new OrderSent($order), function ($message) use ($try) {
        $message->attach($try, 'invoice.pdf', [
            'mime' => 'application/pdf',
        ]);
    });

And in my mail class, this:

/**
 * Create a new message instance.
 *
 * @return void
 */
public function __construct(Order $order)
{
    $this->order = $order;
}

/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->markdown('mail.customer.order-sent');
}