Lestah

Lestah

Member Since 1 Year Ago

Experience Points 5,170
Experience Level 2

4,830 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 21
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

21 Apr
1 month ago

Lestah left a reply on Object Of Class Illuminate\Database\Eloquent\Collection Could Not Be Converted To Int

Thanks for responding figure it out i just need to log out as a user to run the test. Sorry for asking this question

Lestah started a new conversation Object Of Class Illuminate\Database\Eloquent\Collection Could Not Be Converted To Int

it says the error is on my index.blade.php


@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">
                    <div class="d-flex align-items-center">
                        <h2>All Questions</h2>
                        <div class="ml-auto">
                            <a href="{{ route('questions.create') }}" class="btn btn-outline-secondary">Ask Question</a>
                        </div>
                    </div>
                </div>

                <div class="card-body">
                    @include('layouts._messages')
                    @foreach($questions as $question)
                        <div class="media">
                            <div class="d-flex flex-column counters">
                                <div class="vote">
                                    <strong>{{ $question->votes }}</strong> {{ str_plural('vote', $question->votes) }}
                                </div>
                                <div class="status {{ $question->status }}">
                                    <strong>{{ $question->answers_count }}</strong> {{ str_plural('answer', $question->answers_count) }}
                                </div>
                                <div class="view">
                                    {{ $question->views . " " . str_plural('view', $question->views) }}
                                </div>
                            </div>
                            <div class="media-body">
                                <div class="d-flex align-items-center">
                                <h3 class="mt-0"><a href="{{ $question->url }}">{{ $question->title }}</a></h3>
                                    <div class="ml-auto">
                                        @can ('update', $question)
                                        <a href="{{ route('questions.edit', $question->id) }}" class="btn btn-sm btn-outline-info">Edit</a>
                                        @endcan
                                        @can ('delete', $question)
                                        <form class="form-delete" method="post" action="{{ route('questions.destroy', $question->id) }}">
                                            @method('DELETE')
                                            @csrf
                                            <button type="submit" class="btn btn-sm btn-outline-danger" onclick="return confirm('Are your sure')">Delete</button>
                                        </form>
                                        @endcan
                                    </div>
                                </div>
                               
                                <p class="lead">
                                    Asked by
                                    <a href="{{ $question->user->url }}">{{ $question->user->name }}</a>
                                    <small class="text-muted">{{ $question->created_date }}</small>
                                </p>
                                {{ str_limit($question->body, 250) }}
                            </div>
                        </div>
                        <hr>

                    @endforeach
                    {{ $questions->links() }}
                </div>
            </div>
        </div>
    </div>
</div>
@endsection


C:\newProjects\htdocs\projectvue\app\Policies\QuestionPolicy.php


 public function delete(User $user, Question $question)
    {
        return $user->id === $question->user_id && $question->answers < 1;
    }

this the first time I've encounter this error what does it mean how to solve it?

18 Apr
1 month ago

Lestah left a reply on Guidelines For Posting On Laracasts.com

@MSTNORRIS - how can i include a screenshot on laracast when i ask queations

Lestah started a new conversation How To Include Screenshot In Your Question

just want to include some screenshots here so i can ask a clear question please help thanks

17 Apr
1 month ago

Lestah started a new conversation I Use The Make:auth But Login Nav Display Is Distorted When I @extend

this is the localhost:8000 welcome.blade.php


<blockquote class="imgur-embed-pub" lang="en" data-id="Ryg8J8A"><a href="//imgur.com/Ryg8J8A">View post on imgur.com</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

when i did php artisan make:auth and copy the home.blade.php of it. this is the result


<blockquote class="imgur-embed-pub" lang="en" data-id="FTJTT08"><a href="//imgur.com/FTJTT08">View post on imgur.com</a></blockquote><script async src="//s.imgur.com/min/embed.js" charset="utf-8"></script>

the login nav is distorted

16 Apr
1 month ago

Lestah left a reply on Laravel Upgrade To 5.8 Error

@STEREOH - if in case something is not right can i undo things. i dont want to mess up my old xampp with version php5.6.4 cause i have a lot of projects in there

Lestah left a reply on Laravel Upgrade To 5.8 Error

thanks for responding is it possible to install another version of composer to run a php7.1.2 on my other xampp or it will mess up my system btw I'm using windows os

15 Apr
1 month ago

Lestah started a new conversation Laravel Upgrade To 5.8 Error

I have two version of xamp installed on my laptop the other xampp is with php 7.1.2 version when i tried to do a composer update on the project that is located on xampp with version php 7.1 it says


Problem 1
    - This package requires php ^7.1.2 but your PHP version (5.6.30) does not satisfy that requirement.
Problem 2
    - laravel/framework v5.8.9 requires php ^7.1.3 -> your PHP version (5.6.30) does not satisfy that requirement.


it seems like composer is only detecting php 5.6 on my other xampp. how do I solve this error?

14 Apr
1 month ago

Lestah left a reply on Laravel Route Error

@DIEGOAURINO - HI thanks for responding yup I'm aware of it. i just want to change the question/{question} to question/{slug} to make it more user friendly instead of displaying the question id in the url. but this error wont let me do it

Lestah started a new conversation Laravel Route Error

On my web.php I'm trying to change one of the route from


question/{id} to question/{slug}

//so i did this

Route::resource('questions', 'QuestionsController')->except('show');
Route::get('/questions/{slug}', '[email protected]')->name('questions.show');

//but whenever i check php artisan route:list it says
//Call to a member function except() on null

what does it mean? how can i solve this error?

08 Apr
1 month ago

Lestah left a reply on Upgrade To Laravel 5.7

@SNAPEY - 5.8 is out now? can i go straight to 5.4 to 5.8 or do i have to go throught each

07 Apr
1 month ago

Lestah left a reply on Upgrade To Laravel 5.7

@SNAPEY - i see so it will not affect my other projects that was in version 5.4?

Lestah started a new conversation Upgrade To Laravel 5.7

i dont want my other projects to be upgraded to laravel 5.7 but some of my projects need to upgrade to laravel 5.7. can i upgrade only one specific project or if i upgrade to 5.7 does it affect all the projects that i have?

31 Mar
1 month ago

Lestah left a reply on Npm Is Not Recognized As An Internal And External Command

@SNAPEY - yes i search for it and i found on laravel documentation that i need to install node.js first now i tried again on my command line type again npm install and something is installing. new to this kind of stuff vue

Lestah started a new conversation Npm Is Not Recognized As An Internal And External Command

Thats what i get when i tried to type npm install on my command line. How can i solve this error?

29 Mar
1 month ago

Lestah left a reply on How Can I Decrease Stocks Base On Order Quantity

@SCREENBEETLE - By the way if i have sizes on each product can i do this

foreach( $productDetails as $pro) {
    ProductsAttribute::where('product_id',  $pro->product_id && 'size','$pro->size')->decrement('stock', $pro->quantity);
}

Lestah left a reply on How Can I Decrease Stocks Base On Order Quantity

@SCREENBEETLE - hey man thanks for responding its my fault forgot semicolon at the end its now working can get the product_id and the quantity sorry I'm kind of less focus today but thanks for helping me


foreach( $productDetails as $pro) {
product_id = $pro->product_id
quantity = $pro->quantity
}


Lestah left a reply on How Can I Decrease Stocks Base On Order Quantity

@SCREENBEETLE - when i echo "

"; print_r($productDetails); die; here's what i get


Illuminate\Support\Collection Object
(
    [items:protected] => Array
        (
            [0] => stdClass Object
                (
                    [id] => 66
                    [product_id] => 7
                    [product_name] => Oflix chair
                    [product_code] => ofc-1
                    [product_color] => white
                    [size] => 
                    [price] => 2200
                    [quantity] => 2
                    [user_email] => [email protected]
                    [session_id] => IGsv299DfumXFbePkBE64DozWjDCTU3i7XLfbKoL
                    [created_at] => 
                    [updated_at] => 
                )

            [1] => stdClass Object
                (
                    [id] => 67
                    [product_id] => 8
                    [product_name] => Gucci Porcelain vase
                    [product_code] => gpv-1
                    [product_color] => light pink
                    [size] => 
                    [price] => 1200
                    [quantity] => 2
                    [user_email] => [email protected]
                    [session_id] => IGsv299DfumXFbePkBE64DozWjDCTU3i7XLfbKoL
                    [created_at] => 
                    [updated_at] => 
                )

            [2] => stdClass Object
                (
                    [id] => 68
                    [product_id] => 10
                    [product_name] => tagaytay flower pots
                    [product_code] => tfp-1
                    [product_color] => white
                    [size] => 
                    [price] => 1500
                    [quantity] => 1
                    [user_email] => [email protected]
                    [session_id] => IGsv299DfumXFbePkBE64DozWjDCTU3i7XLfbKoL
                    [created_at] => 
                    [updated_at] => 
                )

        )

)

that's because i added 3 products on the cart with different quantity just want to get the product id and quantity so i can put it the loop but how?

Lestah left a reply on How Can I Decrease Stocks Base On Order Quantity

@SCREENBEETLE - yup thinking of doing that but before looping I'm trying to get the product id and quantity but its not working

$productDetails = DB::table('cart')->where(['user_email' => $user_email])->get();

foreach( $productDetails as $pro) {
product_id = $pro->product_id
quantity = $pro->quantity
}

and the loop starts here

how can i pass the product_id and quantity to the loop i try to echo its undefined variable

28 Mar
1 month ago

Lestah left a reply on How Can I Decrease Stocks Base On Order Quantity

@SNAPEY - i use get to get() all the products that are added on the cart then get the product_id and quantity so can decrease the stock based on the desired user quantity.

example user added the 3 products on the cart then have a desired quantity PRODUCTS QUANTITY product1 5 orders product2 1 0orders product3 2 orders

now product1 stock will decrease the quantity by 5 same goes for the two products

Lestah left a reply on How Can I Decrease Stocks Base On Order Quantity

@SCREENBEETLE - how can i get the product_id and quantity Ive tried doing this

foreach( $productDetails as $pro) {
product_id = $pro->product_id
quantity = $pro->quantity
}

there's no error i tried to echo $product_id; die seems like nothing cant see the data product_id

Lestah started a new conversation How Can I Decrease Stocks Base On Order Quantity

if($data['payment_method']=="COD"){

            //this will get the details of all product inside cart
            $productDetails = DB::table('cart')->where(['user_email' => $user_email])->get();
            //echo "<pre>"; print_r($productDetails); die;
            
    //this part i want to get the product_id and the quantity that was ordered by the user
            
            ProductsAttribute::where('product_id',$product_id)->decrement('stock',$quantity);
            
            return redirect('/thanks');    
        } else {
            return redirect('/paypal');
        }
12 Mar
2 months ago

Lestah left a reply on How Can I Make A Data Available To All Views

i get local host can't handle request when i @incude('products.cart') on front_header.blade.php

Lestah left a reply on How Can I Make A Data Available To All Views

oh ok I will try to include didnt see that reply

Lestah left a reply on How Can I Make A Data Available To All Views

I haven't thought about it $userCart->count() thanks for this advice... i to put all my codes on function boot and left the controller with just the


public function cart()
{
    return view('products.cart');
}

it gives me no errors but there some issue like when i try to add item on the cart it says i already added that item and i know that i is already in the cart but when i checked the cart item list there's none. so undo this what i did is i put all the codes back to my controller and put the code as well in my boot function result is it runs and i can see the cart how many items are there its now working but on index or homepage it displays zero

now my controller cart function and boot function have this


public function boot()
{
    $session_id = Session::get('session_id');

    $userCart = DB::table('cart')->where(['session_id'=>$session_id])->get();

    //get the image from product table
    foreach($userCart as $key => $product) { // this is not a good way to do this
        $productDetails = Product::where('id',$product->product_id)->first();
        $userCart[$key]->image = $productDetails->image;
    }

    View::share('userCart', $userCart);
}

this is my cart function


public function cart()
    {
        $session_id = Session::get('session_id');

        $userCart = DB::table('cart')->where(['session_id'=>$session_id])->get();
       
        foreach($userCart as $key => $product) {
            
            $productDetails = Product::where('id',$product->product_id)->first();
            $userCart[$key]->image = $productDetails->image;
        }
        return view('products.cart')->with(compact('userCart'));
    }


Lestah left a reply on How Can I Make A Data Available To All Views

@CRONIX - this is the full version of my controller


public function cart()
    {
        //to get the session variable created at add to cart function
        $session_id = Session::get('session_id');

        $countCartItems = DB::table('cart')->where(['session_id'=>$session_id])->count();
    //this is just to retrieve the number of items in cart like fore example 3

        $userCart = DB::table('cart')->where(['session_id'=>$session_id])->get();
        //echo "<pre>"; print_r($userCart); die;

        //because cart table doesnt have image column on database

        //get the image from product table
        foreach($userCart as $key => $product) {
            //to check if were getting the product_id
            //echo $product->product_id; die;
            
            $productDetails = Product::where('id',$product->product_id)->first();
            //this will get the image
            $userCart[$key]->image = $productDetails->image;
        }
        //echo "<pre>"; print_r($userCart); die;
        return view('products.cart')->with(compact('userCart','countCartItems'));
    }

this works only on cart.blade.php when i go to index or other pages its giving me errors index undefined

Lestah left a reply on How Can I Make A Data Available To All Views

@COBS - when i do this



view::share('countCartItems', $countCartItems);


result is is cart(COUNTCARTITEMS) on everypage

then i tried doing this on my app service provider


$session_id = Session::get('session_id');
        $countCartItems = DB::table('cart')->where(['session_id'=>$session_id])->count();
        View::share('countCartItems');

result is none but there's no errors cart displays nothing like cart()

Lestah left a reply on How Can I Make A Data Available To All Views

@COBS - i saw the link could you tell me what to put in this values


View::share('key', 'value');

Lestah started a new conversation How Can I Make A Data Available To All Views

i have a cart button whick displays how many cart items on the cart like this cart ( 0 ) what i did is

here's my controller


public function cart()
{
    $session_id = Session::get('session_id');
    $userCart = DB::table('cart')->where(['session_id'=>$session_id])->get();
    return view('products.cart')->with(compact('countCartItems'));
}

on my view cart.blade.php i can see that it's woking it display how many items in cart with the same session_id now my problem is when i go to other pages like the homepage i get this error Undefined variable: countCartItems

how can i make this {{ $countCartItems }} variable to be available in all pages

10 Mar
2 months ago

Lestah left a reply on Trying To Pass Url Variable But I Got This NotFoundHttpException

Sorry i was less focus today cause of my fever i forgot that i deleted the url column on my categories table reason why no data on the url its now ok thanks again snapey :D

Lestah started a new conversation Trying To Pass Url Variable But I Got This NotFoundHttpException

here's my listing.blade.php


 @foreach($categories as $cat)
                <ul>
                    <li class=""><a href="{{ url('/products/'.$cat->url ) }}">{{ $cat->name }}</a></li>    
                </ul>
@endforeach


here's my controller


public function products($url = null)
    {
        $categories = Category::where('parent_id', 0)->get();
        $productsAll = Product::where('url', $url)->get();
      

        return view('products.listing')->with(compact('categories','productsAll'));   
    }

here's my route


Route::get('/products/{url}','[email protected]');

Im just trying to get this output

localhost:8000/products/mobile

whenever i click the href

I'm just getting this with the error

localhost:800/products/ reason why i get to the error page NotFoundHttpException

not getting the url mobile that i pass what could be wrong?

Lestah left a reply on Trying To Get Property Of Non-object

Hey snapey thanks for responding just need to restart laravel its now working :D

Lestah left a reply on Trying To Get Property Of Non-object

i was able to display get rid of the error if i remove the


 foreach($products as $key => $val){
            $category_name = Category::where(['id'=>$val->category_id])->first();
            $products[$key]->category_name = $category_name->name;
        }

//and remove

<td>{{ $product->category_name }}</td>

but the problem is i wont be able to include the category name column on my table

Lestah left a reply on Trying To Get Property Of Non-object

@SNAPEY - yup i did try to use [' '] instead of the arrow still the same error it says trying to get the property of nonobject what i remember is i did $category_name = Category::where(['id'=>$val->category_id])->first(); inside the loop on my past project with the same concept it works fine because i need to get he category id and category name on my products table. on my category model it has a relation of has to many like this


<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    public function categories() 
    {
        return $this->hasMany('App\Category','parent_id');
    }
}

so i could display category id and category name on my products table

Lestah started a new conversation Trying To Get Property Of Non-object


public function viewProducts()
    {
        $products = Product::get();
        
        foreach($products as $key => $val){
            $category_name = Category::where(['id'=>$val->category_id])->first();
            $products[$key]->category_name = $category_name->name;
        }
        //echo "<pre>"; print_r($products); die;
        $products = json_decode(json_encode($products));
        return view('admin.products.view_products')->with(compact('products'));
    }

just want to display data on my table


<tbody>
                @foreach($products as $product)
                <tr {{-- class="table-info" --}}>
                    <td>{{ $product->id }}</td>
                    <td>{{ $product->category_id }}</td>
                    <td>{{ $product->category_name }}</td>
                    <td>{{ $product->product_name }}</td>
                    <td>{{ $product->product_code }}</td>
                    <td>{{ $product->product_color }}</td>
                    <td>{{ $product->url }}</td>
                    <td>{{ $product->price }}</td>
                    <td class="center">@if ($product->feature_item == 1) Yes @else No @endif</td>
                    <td>
                    @if(!empty($product->image))
                      <img src="{{ asset('admin-ui/images/products/small/'.$product->image) }}" style="width:60px;">
                    @endif
                  </td>
                    <td><a href="{{ url('/admin/edit-product/'.$product->id) }}" class="btn btn-outline-primary btn-sm">Edit</a> <a href="{{ url('/admin/add-attributes/'.$product->id) }}" class="btn btn-outline-primary btn-sm">Add</a> <a id="delProduct" rel="{{ $product->id}}" rel1="delete-product" href="javascript:" class="btn btn-outline-danger btn-sm deleteRecord" title="DeleteProduct">Delete</a></td>
                </tr>
                @endforeach
              </tbody>


Lestah left a reply on Is This The Right Way Of Doing This

nah its fine now its working i just forgot to type ->get();

Lestah started a new conversation Is This The Right Way Of Doing This

public function products($url = null)
    {
        $categories = Category::where('parent_id', 0)->get();
        $productsAll = Product::where('category_name', $url);

        //echo "<pre>"; print_r($productsAll); die;
        return view('products.listing')->with(compact('categories','productsAll'));
        
    }

i don't get any data on productsAll i just want to get all the products where category name is equal to url


$productsAll = Product::where('category_name', $url);

08 Mar
2 months ago

Lestah left a reply on Syntax Error, Unexpected '{'

Sorry guys its my fault

this is how it should be

if(empty($data['category_id']))

remove the extra (

Lestah started a new conversation Syntax Error, Unexpected '{'

it says in line 17

public function addProduct(Request $request)
    {
        if($request->isMethod('post')){
            $data = $request->all();
            //echo "<pre>"; print_r($data); die;
            if(empty($data(['cateogry_id'])){
                return redirect()->back()->with('flash_message_error','Under Category is mssing');
            }

this line of code is up till line 20? did i miss something?

03 Mar
2 months ago

Lestah started a new conversation I Didn't Get Anything When I Use If(Auth::check())

i have this controller before i was able to display all the items that are added on the cart

this my controller


public function cart()
    {   
        $session_id = Session::get('session_id');
        $userCart = DB::table('cart')->where(['session_id'=>$session_id])->get();
     
        //echo "<pre>"; print_r($userCart); die;

        //to get the image from product table
        foreach($userCart as $key => $product) {
            //to check if were getting the product_id
            //echo $product->product_id; die; 
            $productDetails = Product::where('id',$product->product_id)->first();
            //this will get the image
            $userCart[$key]->image = $productDetails->image;
        }
        return view('products.cart')->with(compact('userCart'));
    }

now i updated my controller to this to check if the user is logged in first


public function cart()
    {   
        if(Auth::check()){
            $user_email = Auth::user()->email;
            $userCart = DB::table('cart')->where(['user_email' => $user_email])->get();     
        }else{
            $session_id = Session::get('session_id');
            $userCart = DB::table('cart')->where(['session_id' => $session_id])->get();    
        }

        //to get the image from product table
        foreach($userCart as $key => $product) {
            //to check if were getting the product_id
            //echo $product->product_id; die; 
            $productDetails = Product::where('id',$product->product_id)->first();
            //this will get the image
            $userCart[$key]->image = $productDetails->image;
        }
        return view('products.cart')->with(compact('userCart'));
    }

now when i click add to cart button there's is no error it says i added the item but when i check the cart page there's no display of the item i added and then i tried to add it again it now says i already added the item on the cart

I dont have any errors what could be wrong? is it because of the if(Auth::check)?

26 Feb
2 months ago

Lestah left a reply on What Does It Mean Undefined Offset: 1

@CRONIX - yup planing on doing that later. right now I'm just using flash message.

Lestah left a reply on What Does It Mean Undefined Offset: 1

@cronix thanks for making me realize that haha!

Lestah left a reply on What Does It Mean Undefined Offset: 1

hey guys just want to let u know there's nothing wrong with the code... It's my fault I'm sorry reason why I'm getting offset error is because when i try to test I always forget to select on my drop-down list where i can get a data i just rush on clicking the button without selecting how can i delete this question?

Lestah left a reply on What Does It Mean Undefined Offset: 1

@CRONIX - i tested this before it works i can get the value of size


public function addtocart(Request $request)
    {
        $data = $request->all();
    echo "<pre>"; print_r($data); die;


and now try to test again this is what happen


Array
(
    [_token] => zWJ3fwrMk9iDtu7UTPdSOxslRGUYwOXZVyI7Fopp
    [product_id] => 31
    [product_name] => Uniqlo
    [product_code] => u-1
    [product_color] => white
    [price] => 800
    [size] => 
    [quantity] => 1
)

Lestah left a reply on What Does It Mean Undefined Offset: 1

@CRONIX - i see reason why i use explode on dash because this is the result I'm getting 7-small. 7 is the product_id small is the size and i want to store only the size which small I was able to insert the data with this code


DB::table('cart')->insert(['product_id'=>$data['product_id'],'product_name'=>$data['product_name'],'product_code'=>$data['product_code'],'product_color'=>$data['product_color'],'price'=>$data['price'],'size'=>$product_size,'quantity'=>$data['quantity'],'user_email'=>$data['user_email'],'session_id'=>$session_id ]);

I did some changes on this query like


'data'=>'product_code'=>$getSKU->sku


this is the $getSKU variable


$getSKU = ProductsAttribute::select('sku')->where(['product_id'=>$data['product_id'],'size'=>$product_size])->first();

now I'm getting the error Undefined offset: 1

when i dd

dd($sizelDArr)


array:1 [▼
  0 => ""
]

here' what I'm getting

Lestah started a new conversation What Does It Mean Undefined Offset: 1

I'm just trying to insert data on my cart table like this


$sizeIDArr = explode('-',$data['size']);
$product_size = $sizeIDArr[1]; //this the line that's giving me error

DB::table('cart')->insert(['product_id'=>$data['product_id'],'product_name'=>$data['product_name'],'product_code'=>$getSKU['sku'],'product_color'=>$data['product_color'],'price'=>$data['price'],'size'=>$product_size,'quantity'=>$data['quantity'],'user_email'=>$data['user_email'],'session_id'=>$session_id ]);

21 Feb
3 months ago

Lestah left a reply on How Did It End As An Array?

@CRONIX - I'ma use it always now since its your recommendation... 2000 id yeah i think i wouldn't get a product that much

Lestah left a reply on How Did It End As An Array?

@CRONIX - hey guys @cronix @snapey thanks for ur help I just solved it what i did is just this on my products controller i query this


$productDetails = Product::with('attributes')->where('id', $id)->first();
and do test like what you advc


and then on my view page i did this like what @cronix suggested


@foreach($productDetails->attributes as $attribute)


and it now displays i just need a couple hours of sleep to figure that one out haha thanks a lot

20 Feb
3 months ago

Lestah left a reply on How Did It End As An Array?

@CRONIX - i got a product_view.blade.php which have a datatable of product ID, category ID, Category Name and so on.. the table contains add edit delete view on the add button i got


<a href="{{ url('/admin/add-attributes/'.$product->id) }}" class="btn btn-success btn-mini">Add</a>


that's why i have a route on my web.php


Route::match(['get', 'post'], '/admin/add-attributes/{id}','[email protected]');


so it will go to my controller addAttributes

when i dd($id); it gives me the product_id that i click on the table which is correct thats what i expect

i tried this removed the relationship


$productDetails = Product::where(['id' => $id])->first();
dd($productDetails);

it gives me this

Product {#241 ▼
  #connection: "mysql"
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:10 [▶]
  #original: array:10 [▶]
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #events: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #guarded: array:1 [▶]
}


i trink I have to troubleshoot more

Lestah left a reply on How Did It End As An Array?

@CRONIX - (1/1) ErrorException Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, string given, called in C:\xampp\htdocs\online-shop\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php on line 131 and defined

this the error i came up.. I'm still trying to search on laravel documentation