johnef_sh

johnef_sh

Member Since 3 Years Ago

Experience Points
7,000
Total
Experience

3,000 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
47
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 2
7,000 XP
Sep
03
1 month ago
Activity icon

Started a new Conversation Get The Most Purchases Product For Current User

I have 3 tables here (order_lists, order_details, products)

Table order_lists contain the following user_id

Table order_details contain the following order_lists_id product_id

Table products contain all the products details.

the three tables are related to each others in models.

I need to select the most purchases items from table order_details based this user_id.

I made very basic Eloquent query which will select 6 products for this user but stuck on how to get the most purchases product

$mostPurchases = OrderList::where( 'user_id', Auth::id() )
                 ->with( [
                   'orderDetails' => function ( $query ) {
                         $query->with( 'productId' );
                    }
                 ] )->take( 6 )->get();

but this didn't work as expected

so I used the DB

DB::table( 'products' )
              ->leftJoin( 'order_details', 'products.id', '=', 'order_details.product_id' )
              ->select( DB::raw( 'count(*) as pro_count, product_id' ) )
              ->leftJoin( 'order_lists', 'order_details.order_lists_id', '=', 'order_lists.id' )
              ->where( 'order_lists.user_id', '=', $usId )
              ->orderBy( 'pro_count', 'DESC' )
              ->groupBy( 'product_id' )
              ->take( 6 )
              ->get();

This working fine but don't get the products details

it just returns the (product_id, and the pro_count)

something like this

        {
            "pro_count": 22,
            "product_id": 733
        },

how can I return the product details with the response.

May
12
5 months ago
Activity icon

Replied to Chack For Input Array If It's Empty Or Not

@FTIERSCH - Thanks this function filled is L5.5 I am using L5.4 so it's has thanks a lot.

Activity icon

Started a new Conversation Chack For Input Array If It's Empty Or Not

I have an input looks like this.

{!! Form::text('inventory[0][amount]', null, ['class'=>'form-control']) !!}
{!! Form::text('inventory[0][expiry_date]', null, ['data-format'=>'D, dd MM yyyy', 'class'=>'form-control']) !!}

print_r( $_POST ); results

 [inventory] => Array ( [0] => Array ( [amount] => 66 [expiry_date] => 2019/05/20 ) )

I am trying to check if the amount and the expiry_date are not null

if ( $input['inventory[0][amount]'] and $input['inventory[0][expiry_date]'] != null )

but I got

Undefined index: inventory[0][amount]

May
06
5 months ago
Activity icon

Replied to Laravel-5.4: Validation Array Field Don't Recognize (*)

@ROBOROBOK - I need this arrays it can't be changed

May
02
5 months ago
Activity icon

Started a new Conversation Laravel-5.4: Validation Array Field Don't Recognize (*)

I am trying to validates fields like this

{!! Form::text('packages[0][price]', null, ['class'=>'form-control', 'placeholder' => trans('interface.price')]) !!}
{!! Form::text('packages[0][unit_count]', null, ['class'=>'form-control', 'placeholder' => trans('interface.unitCount')]) !!}

when I try to make the validation like this

'packages.0.price' => 'required|regex:/^[\d.,]+$/', it works fine

but with (*)

'packages.*.price' => 'required|regex:/^[\d.,]+$/',

it don't work, any ideas please.

May
01
5 months ago
Activity icon

Replied to The Right Way Formatimg The JS Code

@SERGIU17 - will review it thanks

Activity icon

Replied to The Right Way Formatimg The JS Code

@MVD - Yes this worked fine with me, thanks a lot dear MVD

Activity icon

Started a new Conversation The Right Way Formatimg The JS Code

Hi guys good day for you all, I'd like o understand how to format this code

<script>
        let counter = 1;
        let limit = 10;

        function addInput(divName) {
            if (counter === limit) {
                alert("You have reached the limit of adding " + counter + " inputs");
            } else {
                let newdiv = document.createElement('div');
                newdiv.innerHTML = '<div class="col-md-12 col-md-pull-1"><div class="col-md-6">{!! Form::text("measurements[' + (counter + 1) + '][width]", null, ["class"=>"form-control", "placeholder" => trans("interface.width")]) !!}</div>';
                document.getElementById(divName).appendChild(newdiv);
                counter++;
            }
        }
    </script>

Here in Form::text("measurements[' + (counter + 1) + '][width]" I try to put this ' + (counter + 1) + ' in the array index but seems it's not reading the code right.

so what should be the right format here.

thanks

Activity icon

Replied to Insert Multiple Records Into Multiple Tables

@MICHALURVA - Thanks worked as expected

Apr
30
5 months ago
Activity icon

Replied to Insert Multiple Records Into Multiple Tables

Let's make it more simple

Here I made the HTML FORM like this

{!! Form::text('measurements[measurement][width]', null, ['class'=>'form-control', 'placeholder' => trans('interface.width')]) !!}
{!! Form::select('measurements[measurement][width_u]', $measurements, null, [ 'class'=>'form-control', 'placeholder' => trans('interface.justSelect') ]) !!}

to get the measurements in array and each array has the values and after that loop but still getting the array wrong

"measurements" => array:1 [▼
    "measurement" => array:10 [▼
      "width" => "7"
      "width_u" => "1"
      "length" => "1"
      "length_u" => "1"
      "height" => "4"
      "height_u" => "1"
      "weight" => "5"
      "weight_u" => "2"
      "volume" => "6"
      "volume_u" => "2"
    ]
  ]

if I have two measurements it should be

"measurements" => array:2 [▼
    "measurement" => array:10 [▼
      "width" => "7"
      "width_u" => "1"
      "length" => "1"
      "length_u" => "1"
      "height" => "4"
      "height_u" => "1"
      "weight" => "5"
      "weight_u" => "2"
      "volume" => "6"
      "volume_u" => "2"
    ]
"measurement" => array:10 [▼
      "width" => "5"
      "width_u" => "6"
      "length" => "1"
      "length_u" => "7"
      "height" => "4"
      "height_u" => "8"
      "weight" => "5"
      "weight_u" => "2"
      "volume" => "6"
      "volume_u" => "2"
    ]
  ]

any idea?

Activity icon

Replied to Insert Multiple Records Into Multiple Tables

@AJITHLAL - Got Illegal string offset 'weight'

Activity icon

Started a new Conversation Insert Multiple Records Into Multiple Tables

I have 3 tables here

products, pck_measurements, packages

I need to insert the product details into products and multiple packages for this product into packages and multiple measurement pck_measurements depending on the packages_id.

Here is what I try (HTML Form)

{!! Form::select('product_category_id', $productsCategory, null, ['class'=>'form-control', 'placeholder' => trans('interface.pleaseSelect')]) !!}
{!! Form::select('tax_id', $taxes, null, ['class'=>'form-control', 'placeholder' => trans('interface.pleaseSelect')]) !!}
{!! Form::text('name_ar', null, ['class'=>'form-control', 'placeholder' => trans('interface.productNameAr')]) !!}
....
//Now comes the package information
{!! Form::text('packages[price]', null, ['class'=>'form-control', 'placeholder' => trans('interface.price')]) !!}
{!! Form::text('packages[unit_count]', null, ['class'=>'form-control', 'placeholder' => trans('interface.unitCount')]) !!}
...
//And here is the measurement
{!! Form::text('measurements[width]', null, ['class'=>'form-control', 'placeholder' => trans('interface.width')]) !!}
{!! Form::select('measurements[width_u]', $measurements, null, ['class'=>'form-control', 'placeholder' => trans('interface.justSelect')]) !!}
{!! Form::text('measurements[length]', null, ['class'=>'form-control', 'placeholder' => trans('interface.length')]) !!}
{!! Form::select('measurements[length_u]', $measurements, null, ['class'=>'form-control', 'placeholder' => trans('interface.justSelect')]) !!}
...

and here is the controller

public function store( ProductRequest $request ) {
        $input = $request->all();

        $input += [
            'ar' => [
                'name'    => $request->name_ar,
                'details' => $request->details_ar
            ],
            'en' => [
                'name'    => $request->name_en,
                'details' => $request->details_en
            ]
        ];


        $product    = ( new Product )->create( $input );
        $product_id = $product->id;


        foreach ( $input['measurements'] as $measurement ) {
            $addMeasurement = ( new PckMeasurement() )->create( [
                'weight'   => $measurement->weight,
                'weight_u' => $measurement->weight_u,
                'length'   => $measurement->length,
                'length_u' => $measurement->length_u,
                'height'   => $measurement->height,
                'height_u' => $measurement->height_u,
                'width'    => $measurement->width,
                'width_u'  => $measurement->width_u,
                'volume'   => $measurement->volume,
                'volume_u' => $measurement->volume_u
            ] );
            $measurements   = $addMeasurement->id;
        }

        foreach ( $input['packages'] as $package ) {
            ( new Package() )->create( [
                'price'              => $input['packages']['price'],
                'unit_count'         => $input['packages']['unit_count'],
                'product_id'         => $product_id,
                'pck_measurement_id' => $measurements
            ] );
        }

        return redirect()->route( 'product.create' )
                         ->with( 'success', 'Product added Successfully' );
    }

When I try to add the measurement like this

'weight' => $measurement->weight,

Got

trying to get property of non object

any help will be appreciated