prince69

Member Since 2 Months Ago

Experience Points
730
Total
Experience

4,270 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
2
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 1
730 XP
Mar
08
1 month ago
Activity icon

Started a new Conversation How To Store & Dispaly An Item Using Ajax Without Reload Page

Hi, I want to store data in database using ajax & want to display stored data into blade without refreshing the page. Data is stored successfully but I don't know how to load data without refreshing the page.

Here is my controller code

	    $product= Product::create([
            'title' 	  => $request->title,
            'description' => $request->description,
        ]);

        $data       		 = array();
        $data['success']     = 'datahas been added';
        $data['title']       = $product->title;
        $data['description'] = $product->description;
        $data['id'] = $product->id;

        return response()->json(['status' => true, 'data' => $data]);

Here is my ajax request

		   var config = {
                  routes: {
                    store: "{!! route('slider.store') !!}",
        }
    };

$(document).on('submit', '.submitForm', function(e) {
        e.preventDefault();

        $.ajax({
            url: config.routes.store,
            method: "POST",
            data: new FormData(this),
            contentType: false,
            cache: false,
            processData: false,
            dataType: "json",

            success: function(response) {
                if (response.status == true) {
                    console.log(response.data);                                   
               }
            },

        });


    });

Here is the data table in blade

		   <table class="table table-hover text-center" id="dataTable">
<thead>
    <tr>
        <th scope="col">Image</th>
        <th scope="col">Title</th>
        <th scope="col">Description</th>
        <th scope="col">Action</th>
    </tr>
</thead>
<tbody>
    @if (!empty($products)) @foreach ($products as $key => $product)
    <tr>
        <td>
            <img src="{{ asset('/images/' . $product->image) }}" alt="" />
        </td>
        <td>{{ $product->title?? 'not found' }}</td>
        <td>{{ $product->description ?? 'not found' }}</td>
        <td>
            <a href="#" onclick="edit({{ $product->id }})"><i class="fas fa-pencil-alt text-secondary mr-3"></i></a>
            <a href="#" onclick="delete({{ $product->id }})"><i class="far fa-trash-alt ms-text-danger"></i></a>
        </td>
    </tr>
    @endforeach @endif
</tbody>

Can anyone tell me how can I display stored data into above table without refreshing the page?

Feb
27
1 month ago
Activity icon

Replied to How To Select Only Specific Attributes With Nested Eager Loading

@corvs can you explain the way how can I select columns with nested eager loading? I tried this

    $user_order_summary = Order::with(['orderFoodItems' => function ($query) {
        $query->select(['name', 'image']);
    }, 'orderFoodItems.price' => function ($query) {
        $query->select(['id','original_price']);
    }])->findOrFail($id);

In this way I get orderFoodItems specific attributes but I did not get any attributes from price table

Activity icon

Started a new Conversation How To Select Only Specific Attributes With Nested Eager Loading

Hey is it possible to get specific attributes with nested eager loading? Here is my controller method

public function viewOrder($id) {
    $view_order = Order::with('user.billing_address', 'orderFoodItems.price')->findOrFail($id);
    return response()->json($view_order, 200);
}

And It returns this

		{
"id": 14,
"quantity": 200,
"price": 40000,
"discount": null,
"VAT": null,
"order_date_and_time": "2021-02-25T04:23:00.000000Z",
"delevery_date_and_time": "2021-02-28T04:23:00.000000Z",
"user": {
    "id": 3,
    "name": "test",
    "email": "[email protected]",
    "email_verified_at": null,
    "contact": null,
    "image": null,
    "is_admin": 0,
    "created_at": "2021-02-23T06:38:19.000000Z",
    "updated_at": "2021-02-23T06:38:19.000000Z",
    "billing_address": {
        "id": 5,
        "user_id": 3,
        "area": "area",
        "appartment": "appartment",
        "house": "house",
        "zip_code": "zip_code",
        "created_at": 2021-02-25T04:23:00.000000Z,
        "updated_at": "2021-02-25T04:23:00.000000Z"
    }
},
"order_food_items": [
    {
        "id": 7,
        "name": "test product",
        "image": "foods/1692558140173644.jpg",
        "is_visible": 1,
        "is_available": 1,
        "price": [
            {
                "original_price": 250,
                "discounted_price": 200,
                "discount_type": "percent",
                "fixed_value": null,
                "percent_of": 20
            }
        ]
    }
]

}

I don't want to show all attributes. I want to show only specific attributes like this.

         {
"id": 14,
"quantity": quantity,
"price": price,
"discount": discount,
"VAT": VAT,
"order_date_and_time": "order_date_and_time",
"user": {
    "name": "test",
    "email": "[email protected]",
    "contact": contact,
    "image": image,
    "billing_address": {
        "area": "area",
        "appartment": "appartment",
        "house": "house",
        "zip_code": "zip_code",
    }
},
"order_food_items": [
    {
        "name": "name",
        "image": "image",
        "price": [
            {
                "original_price": "original_price",
                "discounted_price": "discounted_price",
            }
        ]
    }
]

}

How can I do that? What is the proper way to get only specific attributes with nested eager loading?

Feb
25
1 month ago
Activity icon

Replied to Can Anyone Explain Me Why It Returns This Output?

I want to get this as output.

{
"id": 17,
"user_id": 6,
"shipping_address_id": null,
"quantity": 3,
"price": 200,
"discount": null,
"VAT": null,
"order_date_and_time": "2021-02-25T04:36:53.000000Z",
"delevery_date_and_time": "2021-02-28T04:36:53.000000Z",
"order_food_items": [
    {
        "id": 8,
        "name": "test product 2",
        "image": "foods/1692575825608852.jpg",
        "is_visible": 1,
        "is_available": 1,
        "price": [
            {
                "original_price": 250,
                "discounted_price": 200,
                "discount_type": "percent",
                "fixed_value": null,
                "percent_of": 20
            }
        ]
    }
]

},

Tell me how can I get that?

Activity icon

Replied to Can Anyone Explain Me Why It Returns This Output?

@tisuchi By this, first I get user's information then 'orders' ,'orderFoodItems' ,'price'. I don't want user information, I only want 'orders' ,'orderFoodItems' and 'price'. How to do that

Activity icon

Started a new Conversation Can Anyone Explain Me Why It Returns This Output?

Hi, see this code

 $user_order = auth()->user()->orders;
    if ($user_order->count()) {
        return response()->json($user_order, 200);
    }

Then I got only this and It is fine.

  {
    "id": 17,
    "user_id": 6,
    "shipping_address_id": null,
    "quantity": 3,
    "price": 200,
    "discount": null,
    "VAT": null,
    "order_date_and_time": "2021-02-25T04:36:53.000000Z",
    "delevery_date_and_time": "2021-02-28T04:36:53.000000Z"
  },

If I add foreach loop into this code by this way

 $user_order = auth()->user()->orders;
    if ($user_order->count()) {
        foreach ($user_order as $order) {
            foreach ($order->orderFoodItems as $product) {
                foreach ($product->price as $price) {
                }
            }
        }

        return response()->json($user_order, 200);
    }

Then I got this output and I want that.

  {
    "id": 17,
    "user_id": 6,
    "shipping_address_id": null,
    "quantity": 3,
    "price": 200,
    "discount": null,
    "VAT": null,
    "order_date_and_time": "2021-02-25T04:36:53.000000Z",
    "delevery_date_and_time": "2021-02-28T04:36:53.000000Z",
    "order_food_items": [
        {
            "id": 8,
            "name": "test product 2",
            "image": "foods/1692575825608852.jpg",
            "is_visible": 1,
            "is_available": 1,
            "price": [
                {
                    "original_price": 250,
                    "discounted_price": 200,
                    "discount_type": "percent",
                    "fixed_value": null,
                    "percent_of": 20
                }
            ]
        }
    ]
},

But ,My question is I didn't return "orderFoodItems" & "price " , I only return $user_order then why I get "order_food_items" & it's "price".

what is the proper way to get output like this?

Feb
17
2 months ago
Activity icon

Replied to How To Get Product & Price When Clicked On Category Using Ajax In Laravel?

It did not work. I got a view in response only but it did not append.

Activity icon

Started a new Conversation How To Get Product & Price When Clicked On Category Using Ajax In Laravel?

I want to get category-wise products when clicked on a specific category usnig ajax. In this method I get product names & images and successfully load them into view with ajax.

public function getProductByCategory($id) {
    $category = FoodItemCategory::find($id);
    $products = $category->foods;

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

By this foreach loop, I get product price but I couldn't pass them into view as ajax response

 foreach ($products as $product) {
        foreach ($product->price as $price) {
            $original_price = $price->original_price ;

        }
    }

here is my ajax success response

       success: function(response) {
                $('.products').empty();

                var href = "{{ route('home') }}/";

                $.each(response, function(key, value) {
                    var url = "{{ route('shop.view', ':id') }}";
                    url = url.replace(':id', value.id);

                    $('.products').append("<div class='col-md-6 col-lg-4'>" +
                        "<div class='item'><div class='thumb'>" +
                        "<a href='" + url +
                        "' class='woocommerce-LoopProduct-link woocommerce-loop-product__link'>" +
                        "<img src='" + href + "images/" + value.image +
                        "' height='280px' width='320px'></a><a href='#' data-id='" + value.id +
                        "' class='button product_type_simple add_to_cart_button ajax_add_to_cart'>Add to cart</a>" +
                        "</div><div class='info'><h5 class='woocommerce-loop-product__title'><a href='" +
                        url + "'>" +
                        value.name + "</a></h5>" +
                        "<span class='price'><span class='woocommerce-Price-amount amount'><span class='woocommerce-Price-currencySymbol'> </span>65" +
                        "</span></span></div></div></div>");
                });
            }

Now, How can I load prices into this success function?

Feb
14
2 months ago
Activity icon

Replied to Image Is Not Display In Server But In Localhost Works Fine

I ran this command locally, then upload it again in server. There is no option to run command in my webserver

Activity icon

Replied to Image Is Not Display In Server But In Localhost Works Fine

yes, console error "404 image not found"

Activity icon

Replied to Image Is Not Display In Server But In Localhost Works Fine

I run this command & I got this "link already exists." . But still image is not showing

Activity icon

Started a new Conversation Image Is Not Display In Server But In Localhost Works Fine

Image in not shown on sever but in locally, It wokrs perefect. In this way, I store image

    if ($request->has('image')) {
        $filename = $request->image->getClientOriginalName();
        $request->image->storeAs('avatar/users/', $filename, 'public');
    }

Here is in view blade

  <img src="{{ asset('/storage/avatar/users/' . auth()->user()->image) }}" >

In locally that works fine but when I upload my project on server, image is not displayed. Can anyone tell me why did it happen? & how to solve it?

Feb
13
2 months ago
Activity icon

Started a new Conversation How To Auto Delete Row After 3 Days ?

I have a cart table where column is

"id"

"product_id"

"user_id "

"quantity "

"price "

"total_price"

Suppose a user add some product in his cart today. If In 3days he doesn't place an order, then his cart will be empty. That means all of his cart id will be null in Database. I don't know how to do that. Can anyone give me sggestion for how to do this?

Feb
10
2 months ago
Activity icon

Started a new Conversation How To Return View With Success Message & Data?

I want to return view with success message and data. I tried this way

 return redirect()->route('some.route')->with(compact('data'))
            ->with('success', 'thank you');

I got success message in that view but variable is not passed. It shows an error "Undefined variable"

May be I tried with wrong way. What is the proper way to pass variable data with success message in return view??

Feb
08
2 months ago
Activity icon

Started a new Conversation How To Prevent Back Button To Go Default Auth Home Page?

After successful login, If click on browser's back button then It goes to this url "http://127.0.0.1:8000/home" . In my project there is no such url. I'm using laravel ui 3 package for authentication. I don't want to go that home page. I deleted this route

 Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])

I made my custom home page where the user is redirected after successful login & It's worked perfect. But the problem is after login, if I click browser's back button then It's go to default home page which is not good.

How to solve that problem?

Feb
07
2 months ago
Activity icon

Started a new Conversation How To Load Data From Controller To View Using Ajax Call In Laravel?

I want to get all products by category when clicked on category name. I get data from database but couldn't load that in view using ajax.

My controller code

 public function getCategoryItems($id) {
    $category = FoodItemCategory::find($id);
    $products = $category->foods()->get();

    $data   = [];
    $image  = [];
    $prices = [];
    foreach ($products as $product) {
        foreach ($product->price as $price) {
            $data[]   = $product->name;
            $image[]  = $product->image;
            $prices[] = $price->discounted_price;

        }
    }
    return response()->json(['data' => $data, 'image' => $image, 'price' => $prices]);

In ajax success response,I'm trying this way

    success: function(response) {
                if (response) {           
                    $.each(response.data, function(key, value) {
                        $.each(response.image, function(key, image) {

                            // console.log(response.products);
                            // var href = window.location.pathname;
                            var href = "{{ route('home') }}/";
                            $("#category").append(
                                "<div class='col-md-11 col-lg-10 col-xl-6 menu-holder left fixed'><a href='' class='menu-thumb'><img src='" +
                                href + "storage/items/food/" + image +
                                "' height='80' width='80'></a>" +
                                "<div class='menu-item'><h5 class='color-fff'><a href=''></a> <span class='dots'>" +
                                value +
                                "</span><span class='price'><span> ৳ </span>21</span></h5><ul><li>" +
                                "<a href=''>" + value +
                                "</a></li></ul></div></div>");

                        });
                    });

but it shows same data twise. Can anyone tell me the right way to view this data using ajax?