johnef_sh

Member Since 4 Years Ago

Experience Points
7,960
Total
Experience

2,040 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
50
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.

  • Community Pillar

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

Level 2
7,960 XP
Jan
26
1 month ago
Activity icon

Replied to Laravel 8 Each Time View Product, Update Array And Save It To Cookies

Thanks man it solved the issue, one thing last to add check if the id already exists in the array ignore it.

Activity icon

Replied to Laravel 8 Each Time View Product, Update Array And Save It To Cookies

Thanks, very much dear. yes it saves the products numbers now. but the output looks something like this array:1 [▼ 0 => ""\"\\\"\\\\\\\"\\\\\\\\\\\\\\\"4\\\\\\\\\\\\\\\"4\\\\\\\"1\\\"1\"1"1" ]

anyway to do it like this

[
    0=>4,
    1=>1,
    2=>5,
]
Jan
25
1 month ago
Activity icon

Replied to Laravel 8 Each Time View Product, Update Array And Save It To Cookies

Thanks for quick replay agree It looks like you are overwriting the existing values of your cookie how to fix it.

Activity icon

Started a new Conversation Laravel 8 Each Time View Product, Update Array And Save It To Cookies

I am trying to implements product recently viewed into my application. I need to add the customers viewed products into cookies, which I will push them latter to my database.

in my ProductController show function I did this.

        $item_array[] = [ $product->id ];
        $item_data    = json_encode( $item_array );
        Cookie::queue( 'recently_viewed', $item_data, 10 );

and in my blade I started to check.

@if(Cookie::get('recently_viewed'))
    @php
        $recently_views = json_decode(Cookie::get('recently_viewed'), true);
    @endphp
    @foreach($recently_views[0] as $recently_view)
        {{ $recently_view }}
    @endforeach
@endif

it works but, I just see one id of product into cookie which's the one I'm standing on.

How to work around this $item_array[] to add the current id into this array.

Jan
04
1 month ago
Activity icon

Replied to Problem With Unique Field Validation On Update

if some one has what I got in Laravel 8 I had to validated two fields ['ar', 'en'] as unique names

and here is what worked for me

return [
                    'name_ar'          => [
                        'required',
                        Rule::unique( 'product_category_translations', 'name' )->ignore( $this->id, 'product_category_id' )->where( function ( $query ) {
                            return $query->where( 'locale', 'ar' );
                        } )
                    ],
                    'name_en'          => [
                        'required',
                        Rule::unique( 'product_category_translations', 'name' )->ignore( $this->id, 'product_category_id' )->where( function ( $query ) {
                            return $query->where( 'locale', 'en' );
                        } )
                    ],
                    'background_color' => 'required',
                ];
Jan
02
1 month ago
Activity icon

Started a new Conversation If Foreach Loop Iteration == 4 Add Html And Continue The Loop

I am trying to do foreach loop and after 4 iteration I need to continue the loop in different html style

Here what I am trying to do.

@foreach($product_categories as $product_category)
                    <li>
                        {!! Html::image('images/productCategories/'.$product_category->image, $product_category->name, ['class'=>'img-fluid nav-drop-list-categories-img']) !!}
                        <a href="{{ URL::route('show.by.categories', $product_category->name) }}">{{ $product_category->name }}</a>
                    </li>
                    @if($loop->iteration == 4)
                        <li>
                            <ul class="mor-slide-open">
                                <li>
                                    {!! Html::image('images/productCategories/'.$product_category->image, $product_category->name, ['class'=>'img-fluid nav-drop-list-categories-img']) !!}
                                    <a href="{{ URL::route('show.by.categories', $product_category->name) }}">{{ $product_category->name }}</a>
                                </li>
                            </ul>
                        </li>
                    @endif
                @endforeach

Dec
20
2 months ago
Activity icon

Replied to 5.1 Factory Twice As Slow As TestDummy

Same here it takes like 25 minutes before it finishes :(

Nov
03
3 months ago
Activity icon

Replied to Laravel Update Form Using Ajax And FomData() Response GET

Maybe this is my issue If using a resource route, make a regular route. can't I use the resource without adding extra routes for update.

Nov
02
3 months ago
Activity icon

Replied to Laravel Update Form Using Ajax And FomData() Response GET

Even try to add {{ method_field('PUT') }}

and I see it in my request

-----------------------------282519258418162750411255371131
Content-Disposition: form-data; name="_method"

PUT

but still no luck same response

Activity icon

Replied to Laravel Update Form Using Ajax And FomData() Response GET

Here what I did for this data.append('_method', 'PUT');

Activity icon

Started a new Conversation Laravel Update Form Using Ajax And FomData() Response GET

I am using Ajax and FormData() to update my data, let me show my code

Route Route::resource( 'product_categories', ProductCategoryController::class );

and here is the important part HTML and AJAX

<form class="form-horizontal" id="form-horizontal" role="form">
                        <div class="form-group hidden">
                            <label class="control-label col-sm-12" for="product-category-id">Product Category
                                id:</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="product-category-id"
                                       name="product-category-id">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-12"
                                   for="product-category-name-ar">{{ trans('interface.nameArabic') }}</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="product-category-name-ar"
                                       name="product-category-name-ar" value="any">
                                <p class="modalErrorProductCategory text-center alert alert-danger hidden"></p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-12"
                                   for="product-category-name-en">{{ trans('interface.nameEnglish') }}</label>
                            <div class="col-sm-10">
                                <input type="text" class="form-control" id="product-category-name-en"
                                       name="product-category-name-en">
                                <p class="modalErrorProductCategory text-center alert alert-danger hidden"></p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-12"
                                   for="product-category-background-color">{{ trans('interface.backgroundColor') }}</label>
                            <div class="col-sm-10">
                                <input type="color" class="form-control" id="product-category-background-color"
                                       name="product-category-background-color">
                                <p class="modalErrorProductCategory text-center alert alert-danger hidden"></p>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="control-label col-sm-12" for="product-category-image">
                                {{ trans('interface.image') }}
                            </label>
                            <div class="col-sm-10">
                                <input type="file" name="product-category-image" class="form-control"
                                       id="product-category-image">
                                <p class="modalErrorProductCategory text-center alert alert-danger hidden"></p>
                            </div>
                        </div>
                    </form>

/*Action on click edit button*/
        // Update Data

        $('.modal-footer').on('click', '.edit', function (e) {
            e.preventDefault();
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            /*var form = $('#form-horizontal')*/
            var data = new FormData($('#form-horizontal')[0]);
            data.append('_method', 'PUT');

            $.ajax({
                type: "post",
                url: "{{ url('administration/product_categories') }}" + "/" + $('#product-category-id').val(),
                data: data,
                processData: false,
                contentType: false,
                error: function (data) {
                    $('#myModal').modal('show');
                    toastr["error"]("Check your inputs for errors", "Attention!!");
                    toastr.options = {
                        "closeButton": true,
                        "positionClass": "toast-top-right",
                        "showDuration": "300",
                        "hideDuration": "1000",
                        "timeOut": "5000",
                        "extendedTimeOut": "1000",
                        "showEasing": "swing",
                        "hideEasing": "linear",
                        "showMethod": "fadeIn",
                        "hideMethod": "fadeOut"
                    };
                    if (data.error(productCategory)) {
                        $('.modalErrorProductCategory').removeClass('hidden');
                        $('.modalErrorProductCategory').text(data.responseJSON.productCategory[0]);
                    }
                },

                success: function (data) {
                    $('#myModal').modal('hide');
                    $('.modalErrorProductCategory').addClass('hidden');
                    toastr["success"]("ProductCategory successfully edited", "Success!");
                    toastr.options = {
                        "closeButton": true,
                        "positionClass": "toast-top-right",
                        "onclick": null,
                        "showDuration": "300",
                        "hideDuration": "1000",
                        "timeOut": "5000",
                        "extendedTimeOut": "1000",
                        "showEasing": "swing",
                        "hideEasing": "linear",
                        "showMethod": "fadeIn",
                        "hideMethod": "fadeOut"
                    };
                    $('.item' + data.id).replaceWith("<tr class='item" + data.id + "'><td>" + data.id + "</td><td>" + data.translations[0]['name'] + "</td><td>" + data.translations[1]['name'] + "</td><td>" + data.background_color + "</td><td><img src='../../../" + data.image + "' alt='0000' style='width: 50px;'></td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-name-ar='" + data.translations[0]['name'] + "' data-name-en='" + data.translations[1]['name'] + "' data-background-color='" + data.background_color + "'><span class='fa fa-pencil-square-o'></span> {{ trans('interface.edit') }}</button> <button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-name='" + data.name + "'><span class='fa fa-trash'></span> Delete</button></td></tr>");
                }
            });

        }); 

my Request gose OK Some this like this

POSThttp://localhost:8000/administration/product_categories/1

-----------------------------18998142404146031480821803985
Content-Disposition: form-data; name="product-category-id"

1
-----------------------------18998142404146031480821803985
Content-Disposition: form-data; name="product-category-name-ar"

اÙاطعÙØ©
-----------------------------18998142404146031480821803985
Content-Disposition: form-data; name="product-category-name-en"

Food
-----------------------------18998142404146031480821803985
Content-Disposition: form-data; name="product-category-background-color"

#00ff00
-----------------------------18998142404146031480821803985
Content-Disposition: form-data; name="product-category-image"; filename="Slide_2_Ar.jpg"
Content-Type: image/jpeg
....

but the response is GET

GEThttp://localhost:8000/en/administration/product_categories/1
message "Method App\Http\Controllers\Admin\ProductCategoryController::show does not exist."

in my controller

public function update( Request $request, ProductCategory $productCategory ) {
        dd( $request->all() );
        $productCategory->update( $request->all() );

        $data = ProductCategory::find( $productCategory->id );

        return response()->json( $data );
    }

Nothing is requesting the show route

Why it's returning get?

Sep
29
5 months ago
Activity icon

Started a new Conversation Using Ajax To Put Data In Arrays And Send It To Controller .

First let me start with my HTML code

Notes that I have 3 arrays packages[], packages['measurements'], packages['inventory']

<div class="col-md-4">
         {!! Form::text("packages[$i-1][price]", null, ['class'=>'form-control mandfieldbkg pkgreq pkgnum','id'=>"prices$i", 'oninput'=>'packageupdate()']) !!}
         {!! Form::text("packages[$i-1][unit_count]", null, ['class'=>'form-control mandfieldbkg pkgreq pkgdigits', 'id'=>"units$i", 'placeholder' => trans('interface.unitCount')]) !!}
.....
</div>

<div class="form-group col-md-6">
         {!! Form::text("packages[$i-1][width]", null, ["class"=>"form-control mandfieldbkg pkgreq pkgnum", 'id'=>"width$i", "placeholder" => trans("interface.width")]) !!}
         {!! Form::select("packages[$i-1][width_u]", $measurement_length, null, ["class"=>"form-control mandfieldbkg pkgreq", 'id'=>"width_u$i", "placeholder" => trans("interface.justSelect")]) !!}

         {!! Form::text("packages[$i-1][length]", null, ["class"=>"form-control mandfieldbkg pkgreq pkgnum", 'id'=>"length$i", "placeholder" => trans("interface.length")]) !!}
          {!! Form::select("packages[$i-1][length_u]", $measurement_length, null, ["class"=>"form-control mandfieldbkg pkgreq", 'id'=>"length_u$i", "placeholder" => trans("interface.justSelect") ]) !!}
.....
</div>

<div class="col-sm-3 ">
         {!! Form::text('packages['.($i-1).'][inventory][0][amount]', null, ['class'=>'form-control  pkgdigits', 'placeholder' => trans('interface.quantity')]) !!}
         {!! Form::text('packages['.($i-1).'][inventory][0][expiry_date]', null, ['data-format'=>'D, dd MM yyyy', 'class'=>'form-control datepick ', 'placeholder'=>'yyyy-mm-dd']) !!}
.....
 </div>

Here is my Ajax. not completed yet

jQuery(document).ready(function () {
            jQuery('#submitProduct').click(function (e) {
                e.preventDefault();
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    }
                });

                let packages = $("input[name^='packages']").map(function() {
                    return this.value;
                }).get();

                jQuery.ajax({
                    url: "{{ route('product.store') }}",
                    method: 'post',
                    data: {
                        barcode: jQuery('#barcode').val(),
                        or_pro_units: jQuery('#or_pro_units').val(),
                        cost: jQuery('#cost').val(),
                        tax_id: jQuery('#tax_id').val(),
                        profit_margin: jQuery('#profit_margin').val(),
                        or_pro_price_after_pp: jQuery('#or_pro_price_after_pp').val(),
                        product_category_id: jQuery('#product_category_id').val(),
                        child_category_id: jQuery('#child_category_id').val(),
                        child_category_two_id: jQuery('#child_category_two_id').val(),
                        child_category_three_id: jQuery('#child_category_three_id').val(),
                        name_ar: jQuery('#name_ar').val(),
                        name_en: jQuery('#name_en').val(),
                        image: jQuery('#image').val(),
                        gImg: jQuery('#gImg').val(),
                        details_ar: jQuery('#details_ar').val(),
                        details_en: jQuery('#details_en').val(),
                        packages: packages
                    },
                    success: function (data) {
                        console.log(data)
                    }
                });
            });
        });

and here is part of my controller

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

		if ( $request->hasFile( 'image' ) ) {
			....
			Image::make( $image )->save( 'images/products/thumbs-' . $filename );
			$input['image'] = $filename;
                        .....
		} else {
			$input['image'] = $pro->image;
		}

	
		foreach ( $input['packages'] as $package ) {
			if ( $package['price'] != null && $package['unit_count'] != null ) {
				if ( $low_price > $package['price'] || $low_price == 0 ) {
					$low_price = $package['price'] / $package['unit_count'];
				}
			}
		}
		$input['low_price'] = $low_price;
		$product            = ( new Product )->create( $input );
		$product_id         = $product->id;

		if ( $request->hasFile( 'gImg' ) ) {
			$increment = 0;
			foreach ( $request->gImg as $gImg ) {
				....
				Image::make( $gImg )->save( 'images/products/' . $filename );
				....
			}
		}

		foreach ( $input['packages'] as $package ) {
			if ( $package['price'] != null && $package['unit_count'] != null ) {
				$addPackage = ( new Package() )->create( [
					'price'      => $package['price'],
					'unit_count' => $package['unit_count'],
					'product_id' => $product_id,
				] );

				$package_id = $addPackage->id;
				( new PckMeasurement() )->create( [
					'package_id' => $package_id,
					'width'      => $package['width'],
					'width_u'    => $package['width_u'],
					'length'     => $package['length'],
					'length_u'   => $package['length_u'],
					'height'     => $package['height'],
					'height_u'   => $package['height_u'],
					'weight'     => $package['weight'],
					'weight_u'   => $package['weight_u'],
					'volume'     => $package['volume'],
					'volume_u'   => $package['volume_u']
				] );

				foreach ( $package['inventory'] as $inventory ) {
					( new PackageInventory() )->create( [
						'package_id'  => $package_id,
						'amount'      => $inventory['amount'],
						'expiry_date' => $inventory['expiry_date'],
						'store_id'    => $inventory['inventory'],
						'type'        => $inventory['type'],
						'product_id'  => $product_id,
					] );
				}
			}
		}

How can I get all the values from the HTML and send it with AJAX?

Sep
20
5 months ago
Activity icon

Replied to Count For Loop

Thanks. didn't know about ceil before

Activity icon

Replied to Count For Loop

Sorry I didn't git the all code into here c=0

Sep
19
5 months ago
Activity icon

Started a new Conversation Count For Loop

I have package witch has 5 pieces inside and for say the client request 48 piece. I want to know how many packages should I get.

Here is what I try

$p = 5;
$r = 48;

for ( $x = $p; $x <= $r; $x += $p ) {
	$c ++;
}

but in this case it will output // 9 witch is wrong it should be 10.

any other ways to do this.