tehseen

tehseen

Full stack (Laravel, Woocommerce, Wordpress) Developer at Islamabad Pakistan

Member Since 3 Years Ago

Rawalpindi Pakistan

Experience Points
4,010
Total
Experience

990 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
0
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
4,010 XP
Sep
22
3 days ago
Activity icon

Replied to ZIp Upload Fine But Download Issue.

@sinnbeck Thanks for correction Boss

Activity icon

Replied to ZIp Upload Fine But Download Issue.

okay so needs to change the - to . right ?

Let me check @sinnbeck

Activity icon

Replied to ZIp Upload Fine But Download Issue.

@sinnbeck thanks for reply.

So we have product zip folder where we save name and then we have this below link to download the zip

{{ asset( 'zip/'.$product->product_zip) }}

But i can see in my zip folder the once zip upload the file extension change its no more zip

see the screenshot please https://ibb.co/54yn5f2

Activity icon

Started a new Conversation ZIp Upload Fine But Download Issue.

I have write below code to upload zip however its fine to upload product in folder, But when i download via link the file type change and its no longer useful.

Here is the code to upload zip file

if($request->hasFile('product_zip')) {
            $zip = $request->file('product_zip');
            $filename_zip = time().'-'.uniqid().'-'.$zip->getClientOriginalExtension();
            $location = public_path('zip');
            $zip->move($location, $filename_zip);
            $product->product_zip = $filename_zip;
        } else {
            $product->product_zip = "";
        }
           	

Here is the validation

$this->validate($request, [
      'product_zip' => 'required|file|mimes:zip|max:10000'
]);

Thanks for help in advance

Sep
08
2 weeks ago
Activity icon

Replied to Author And Product Relationship Query Issue

@tisuchi

still the same, but the issue is why we get the all user who don't have any product i only want to get user with products and limit (fetch first 5 or 6 products)

Activity icon

Replied to Author And Product Relationship Query Issue

@a4family

same always get 5 product for only 1 user and then one product for 2.

Collection {#382 ▼
  #items: array:5 [▼
    0 => User {#412 ▶}
    1 => User {#413 ▶}
    2 => User {#414 ▶}
    3 => User {#415 ▶}
    4 => User {#416 ▶}
  ]
}
Activity icon

Replied to Author And Product Relationship Query Issue

@tisuchi

i remove the user_id in my product model but still i get 5 products for user one and 1 product for user 2 but we have 5 for user too

here is the query

$productWithUser = User::with(['products' => function ($query) {

            $query->take(6);
        }])->has('products')->get()->toarray();

Activity icon

Replied to Author And Product Relationship Query Issue

@tisuchi yeah sure here it was

product table in which user_id is foreign key https://ibb.co/sHS5dVL

User table https://ibb.co/jrrJ89j

Activity icon

Replied to Author And Product Relationship Query Issue

@tisuchi

in my user modal

public function products() {
        return $this->hasMany('App\Product');
    }

in my product modal

public function user() {
        return $this->belongsTo('App\User', 'user_id');
    }

is something wrong ? can set user_id in user model not product ?

Activity icon

Replied to Author And Product Relationship Query Issue

@tisuchi

Thanks for reply, the above query will get all user but in relationship for the second user we have 1 product (but second user have 5 products)

Collection {#382 ▼
  #items: array:5 [▼
    0 => User {#412 ▶}
    1 => User {#413 ▼
      #fillable: array:3 [▶]
      +sortable: array:3 [▶]
      #hidden: array:2 [▶]
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:15 [▶]
      #original: array:15 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "products" => Collection {#411 ▼
          #items: array:1 [▼
            0 => Product {#430 ▼
              #fillable: array:4 [▶]
              +sortable: array:4 [▶]
              #connection: "mysql"
              #table: null
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:27 [▶]
              #original: array:27 [▶]
              #changes: []
              #casts: []
              #dates: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: []
              #touches: []
              +timestamps: true
              #hidden: []
              #visible: []
              #guarded: array:1 [▶]
            }
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #visible: []
      #guarded: array:1 [▶]
      #rememberTokenName: "remember_token"
      -roleClass: null
      -permissionClass: null
    }
    2 => User {#414 ▶}
    3 => User {#415 ▶}
    4 => User {#416 ▶}
  ]
}
Activity icon

Started a new Conversation Author And Product Relationship Query Issue

I want to get all author with their product at least 5 but the query is not working

$users = User::with(['products' => function ($query) {
            $query->limit(6);
        }])->get();

the above query will return something like below

Collection {#382 ▼
  #items: array:5 [▼
    0 => User {#412 ▼
      #fillable: array:3 [▶]
      +sortable: array:3 [▶]
      #hidden: array:2 [▶]
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:15 [▶]
      #original: array:15 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▶]
      #touches: []
      +timestamps: true
      #visible: []
      #guarded: array:1 [▶]
      #rememberTokenName: "remember_token"
      -roleClass: null
      -permissionClass: null
    }
    1 => User {#413 ▶}
    2 => User {#414 ▶}
    3 => User {#415 ▶}
    4 => User {#416 ▶}
  ]
}

The first user only have product not all, but in my database both first and second author have product

Its relationship between user/author and products one to many

in my user modal

public function products() {
        return $this->hasMany('App\Product');
    }

in my product modal

 public function user() {
        return $this->belongsTo('App\User', 'user_id');
    }

and in database we have user_id in product table.

Please help

Sep
07
2 weeks ago
Activity icon

Replied to How To Get Products By User In Laravel

yes i have one item for user 2 but it return empty array why ?

Activity icon

Replied to How To Get Products By User In Laravel

I have the with product against user 1 and user 2

Activity icon

Replied to How To Get Products By User In Laravel

but it return 6 user and the only first user have product not others why ?

Activity icon

Replied to How To Get Products By User In Laravel

and the below give result but for second user they haven't give any product

$users = User::with(['products' => function ($query) {
    $query->limit(6);
}])->get();
Activity icon

Replied to How To Get Products By User In Laravel

Thank.

But this only gives me one user

$users = User::with(['product' => function ($query) {
            $query->limit(6);
}])->has('product', '>=', 6)->get();

But we have many users what's the issue with above query.

Activity icon

Started a new Conversation How To Get Products By User In Laravel

I want to display 6 product of each user in slider how i can do this ?

It's a relationship between user and product one to many and user_id is in product table.

Here is the image explanation

https://ibb.co/ZG1VMr4

Activity icon

Replied to Want To Upload Maximum 20mb Zip File.

this error

The product zip must be 50000 kilobytes.

even file is 16mb you can see here

"product_zip" => UploadedFile {#32 ▼
        -test: false
        -originalName: "stock-icon-bulb.zip"
        -mimeType: "application/x-zip-compressed"
        -size: 16285787
        -error: 0
        path: "C:\xampp\tmp"
        filename: "php8FAF.tmp"
        basename: "php8FAF.tmp"
        pathname: "C:\xampp\tmp\php8FAF.tmp"
        extension: "tmp"
        realPath: "C:\xampp\tmp\php8FAF.tmp"
        aTime: 2020-09-07 10:05:50
        mTime: 2020-09-07 10:05:5
Activity icon

Replied to Want To Upload Maximum 20mb Zip File.

It means the validation error like below

$this->validate($request, [
	'product_zip' => 'required|mimes:zip|size:20000',
]);

but still get error the file is 16.58mb

Activity icon

Replied to Want To Upload Maximum 20mb Zip File.

Yes i wrote 50000 but still get error with 20mb file.

Activity icon

Replied to Want To Upload Maximum 20mb Zip File.

Thanks.

So what i write in validation is correct for 20mb ?

Activity icon

Replied to Want To Upload Maximum 20mb Zip File.

thanks for answer but its 200mb isn't i want to validate file upto 20mb not 200mb

Activity icon

Started a new Conversation Want To Upload Maximum 20mb Zip File.

I want to upload 20mb max file (type zip) i write the following validation

$this->validate($request, [
	'product_zip' => 'required|mimes:zip|size:50000',
]);

i also have zip file which is

+files: FileBag {#47 ▼
#parameters: array:1 [▼
      "product_zip" => UploadedFile {#32 ▼
        -test: false
        -originalName: "stock-icon-bulb.zip"
        -mimeType: "application/x-zip-compressed"
        -size: 16285787
        -error: 0
        path: "C:\xampp\tmp"
        filename: "php8FAF.tmp"
        basename: "php8FAF.tmp"
        pathname: "C:\xampp\tmp\php8FAF.tmp"
        extension: "tmp"
        realPath: "C:\xampp\tmp\php8FAF.tmp"
        aTime: 2020-09-07 10:05:50
        mTime: 2020-09-07 10:05:50
        cTime: 2020-09-07 10:05:50
        inode: 0
        size: 16285787
        perms: 0100666
        owner: 0
        group: 0
        type: "file"
        writable: true
        readable: true
        executable: false
        file: true
        dir: false
        link: false
        linkTarget: "C:\xampp\tmp\php8FAF.tmp"

but it throw me validation error, what was wrong please advice.

Jul
23
2 months ago
Activity icon

Replied to How To Get Product Data By Id In Laravel Blade

  1. I have product_zip column in product table.

  2. Am listing all order products in template and i have product id in order so i want to get product_zip by id of product.

$user = Auth::id();

        $orderdata = Order::where('user_id', $user)->get()->toArray();
        $orders = Order::where('user_id', $user)->get();

        $carts = [];
        foreach ($orderdata as $key => $value) {
            $carts[] = unserialize($value['cart']);
        }

        $data = [];
        $data['items'] = [];
        foreach ($carts as $key => $value) {
            foreach ($value->items as $key => $values) {
                $itemDetail=[
                    'name' => $values['item']['product_name'],
                    'id' => $values['item']['id'],
                    'itemprice' => $values['item']['price'],
                    'price' => $values['price'],
                    'qty' => $values['qty']
                ];

                $data['items'][] = $itemDetail;
            }
        }

        $total = 0;
        foreach($data['items'] as $item) {
            $total += $item['itemprice']*$item['qty'];
        }

        $data['total'] = $total;

        return view('frontend.pages.myaccount')->withData($data);

so i have $item['id'] in blade template where i want product_zip info and its in product table but i have product id how i can get ?

Activity icon

Started a new Conversation How To Get Product Data By Id In Laravel Blade

I have order array in template in which i display all data of order.

But i am looking to get the product download link but its in product table i have product id in blade like below

 @foreach($data['items'] as $item)

	//product id
$pid = $item['id];

}

i want to get download some data by product id in blade how i can do ?

May
07
4 months ago
Activity icon

Replied to How To Determine Product Quantity.

If i have 83 it will return me this

Array ( [0] => 15 [1] => 15 [2] => 15 [3] => 15 [4] => 15 [5] => 5 )

but the total is 80 however 3 is still missing so what i can do in this case.

Activity icon

Replied to How To Determine Product Quantity.

Thanks.

So i try with number 9 as customer_request so it will be 5+4 but it still give me

Array
(
    [0] => 5
    [1] => 5
    [2] => 1
)

which is wrong it should give me

Array
(
    [0] => 5
    [1] => 4
)
Activity icon

Started a new Conversation How To Determine Product Quantity.

We have 1 Liter & 5 liter product we received order of 11 Liter. So who i can split those 11 liter in to our products we give two of 5 liter and one of 1 in the above case.

Can any one help please.

i mean how i can split numbers in products count of how i can process ?

May
01
4 months ago
Activity icon

Started a new Conversation Get Product By Filter Specific Category

I have a category single page where i get products by category slug (single category page), also i have relationship between category and product so i get all product by category which is fine (below listed).

$category = Category::where('slug', '=', $slug)->firstOrFail();

$categoryProducts = $category->products()->paginate(24);

//all product by above category 
dd($categoryProducts);

So what i try to do is i want to filter those product via category like what i did in product listing.

 $products = Product::where(function($query){

            $all = Input::has('all') ?  Input::get('all') : null;
            $free = Input::has('price') ?  Input::get('price') : null;
            $popular = Input::has('popular') ? Input::get('popular') : null;
            $paid = Input::has('paid') ? Input::get('paid') : null;

            if(isset($free)){
                $query-> where('price','<=', '0');
            }

            if(isset($popular)){
                $query-> where('popular','=', $popular);
            }

            if(isset($paid)){
                $query-> where('price','>', '0');
            }

        })->paginate(24);

any idea how to achieve this ?

Apr
26
4 months ago
Activity icon

Replied to Fetch & Display Category And Its Products

so did we get pagination with chunk ?

Apr
25
5 months ago
Activity icon

Replied to Fetch & Display Category And Its Products

Thanks for help it woks the only remaining part is how i get previous nest pagination link with our above query

Activity icon

Replied to Fetch & Display Category And Its Products

I guess this will worked.

And who i use paginate with this above query ?

Activity icon

Replied to Fetch & Display Category And Its Products

on my blade i write

@foreach ($categories as $chunk)
					<div class="row mb-4">
						@foreach ($chunk as $category)

							@if($category->products->count() > 0)

								<div class="col-md-3">
			                        <div class="silder-item">
										@foreach($category->products as $product)

											{{$product->product_name }}

										@endforeach
									</div>
									
								</div>

							@endif

						@endforeach
					</div>
				@endforeach
						

this works fine how ever the issue is row and column breaks like below in html image i don't know.

https://ibb.co/nnQ6djF

first row have 4 columns then empty row ? why this ?

Do you have any idea ?

Activity icon

Replied to Fetch & Display Category And Its Products

@tykus Thanks,

in the most inner loop where we have

@foreach ($category->products as $product)

we get

Illuminate\Database\Eloquent\Collection Object
(
    [items:protected] => Array
        (
            [0] => App\Product Object
                (

display correct but loop disturb i need to get only 8 items if available so if i use array_chunk it will give error

thank for your help

Activity icon

Started a new Conversation Fetch & Display Category And Its Products

I have relationship many to many between products & categories.

In my Product Model

public function categories() {
    	return $this->belongsToMany(Category::class, 'category_product');
    }

In my Category Model

 public function products() {
		return $this->belongsToMany(Product::class, 'category_product');
	}

so what i try to get is display category with products just like below image. https://ibb.co/vZy9HDz

each how have 4 categories and then each category display product like in image 2 rows with 4 product each.

in my controller i fetch category with product like below

        $categories = Category::with('products')->get();

Thanks for help in advance

Apr
22
5 months ago
Activity icon

Awarded Best Reply on Can't Write Image Data To Path (Intervention Image Package)

so instead of this

$location = public_path('images/'.$filename);

here is the trick

$location = 'images/'.$filename;

this will work for me

Activity icon

Replied to Can't Write Image Data To Path (Intervention Image Package)

so instead of this

$location = public_path('images/'.$filename);

here is the trick

$location = 'images/'.$filename;

this will work for me

Activity icon

Replied to Can't Write Image Data To Path (Intervention Image Package)

thanks, but still issue

Can't write image data to path (/home/motifsol/Laravel/public_html/images/1587619043.png)
Activity icon

Started a new Conversation Can't Write Image Data To Path (Intervention Image Package)

Hi

I save product image on my local with below code and all works fine.

$image = $request->file('product_image');
            $filename = time() . '.'. $image->getClientOriginalExtension();
            $location = public_path('images/'.$filename);
            Image::make($image)->save($location);
            $product->freature_image = $filename;

But when i live the app to Cpanel it gives me error. I know there must be a path error as all public folder items are in Public_html and all other are in Laravel folder which is also in root but can't understand how to fix it.

Can't write image data to path (/home/motifsol/Laravel/public/images/1587584786.png)

Regards

Apr
13
5 months ago
Activity icon

Replied to How To Get Pivot Table Relationship Products By Category Id

if(isset($category)) {
                $query-> where('categories.id', '=', $category);
            }

still not working

Activity icon

Replied to How To Get Pivot Table Relationship Products By Category Id

here is category model

return $this->belongsToMany(Product::class, 'category_product');

here is my product model

return $this->belongsToMany(Category::class, 'category_product');

i just need to filter product with category id

Activity icon

Replied to How To Get Pivot Table Relationship Products By Category Id

i changed but still get the same error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'categories.id' in 'where clause' (SQL: select count(*) as aggregate from `products` where (`categories`.`id` = 1))
Activity icon

Started a new Conversation How To Get Pivot Table Relationship Products By Category Id

i have relationship in product & category many to many with pivot table i was try to filter product with category like below

$products = Product::where(function($query){

$category = Input::has('filtercategory') ? Input::get('filtercategory') : null;

if(isset($category)) {
      $query-> where('category.id', '=', $category);
}

})->paginate(24);

but i have this below error can any one help

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'category.id' in 'where clause' (SQL: select count(*) as aggregate from `products` where (`category`.`id` = 1))
Apr
09
5 months ago
Activity icon

Started a new Conversation Product Filter Query Return Me 500 Why.

Query filter not working i just use filters but when i set query without filter like below it works but in second case i add the filter but its throw 500 why please help.

This works in first case return all products

$products = Product::where(function($query){
            
})->get();

echo json_encode($products);

But when i try to enter filter by price free or paid it return 500 like below

	
$filterValues = array();
parse_str($request->formData, $filterValues);

$products = Product::where(function($query){

	$free = isset( $filterValues['free'] ) ? 'yes' : null;
	if(isset($free) ){
             $query->orwhere('price','<=','0');
        }
            
})->get();

echo json_encode($products);