vikas_developer

vikas_developer

Member Since 1 Month Ago

Delhi

Experience Points
380
Total
Experience

4,620 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-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 1
380 XP
Oct
19
1 day ago
Activity icon

Replied to JQuery Stop Checkbox Checked If Value Is Empty

Thanks @nakov @sinnbeck . You both are genius. Thanks again for the solution.

Activity icon

Replied to JQuery Stop Checkbox Checked If Value Is Empty

@sinnbeck No, I created a new alert box

Activity icon

Replied to JQuery Stop Checkbox Checked If Value Is Empty

@sinnbeck It is returning [object Object] in alert()

Activity icon

Replied to JQuery Stop Checkbox Checked If Value Is Empty

I have issue in below code.

 if ($(this).data('quantity') == 0) {
            alert('Please Select Item Quantity');
            return false;
        }

Rest of the thing are working fine. Let me explain again.

-First when I click the checkbox with 0 quantity then the message is ok that please select item quantity. -Second right after that when I Increase the quantity 0 to 1 then it should work but not working it is repeating the same alert message.

Activity icon

Replied to JQuery Stop Checkbox Checked If Value Is Empty

@sinnbeck When I click the checkbox second time after increasing quantity with input type number then it is repeating the same alert box. That means it stucks when I select checkbox with 0 quantity.

Activity icon

Started a new Conversation JQuery Stop Checkbox Checked If Value Is Empty

When checkbox is clicked and value is empty it is returning message which is working fine. but when I increase the value then it again giving me the same message. The return false function is stop the further actions please check and help.

For reference code is below :


$(document).ready(function(){
    $("input[name='checkbox[]']").click( function (e) {

        var formData = {
            'user_id'              : $(this).data('user_id'),
            'quantity'             : $(this).data('quantity'),
            'form_status'          : $("input[name='checkbox[]']").is(":checked") ? 1 : 0
        };
        if ($(this).data('quantity') == 0) {
            alert('Please Select Item Quantity');
            return false;
        }

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });

        var ajaxRequest = $.ajax({
            type        : 'POST',
            url           : 'test',
            data        : formData, 
            dataType    : 'json', 
            encode      : true
        })
    });

    $("input[name='quantity[]']").on('change',function(){
        var val = $(this).val();
        var amt = $(this).data('price');
        var id = $(this).data('id');
        var total = val*amt;
        $('#amount_'+id).html(total);
        $("input[name='checkbox[]']").attr("data-quantity",  $(this).val());
    });


});
Activity icon

Replied to How To Print All Selected Items By Logged In User

Ohh Sorry Sorry. let me change.

Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov Yes, the order_id is in the extra_orders table.

After changing below code in ExtraOrder model I got the correct response.

public function orders()
    {
        return $this->belongsTo(Orders::class,'order_id');
    }

Thanks for the quick response.

Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov Thanks for the understanding. I have used and it's working but the order items are coming null.

Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov Above statements are correct but only one scenario is different which is user_id in orders table as it contains only items price and description which is inserted manually. so the user will see a list of items coming from orders table having id,item name,price,quantity & etc. Then Extra Orders table is the main table where all the id,order_id which is foreign key of order table and price, quantity extra. So the user is connected to user_id in Extra Orders table and the order_id is connected to orders table.

Please confirm if you get the problem.

Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov Yes, A user can have many orders. I should be very simple but don't know why its creating problem.

Orders Table contains : all the items with price & Description. ExtraOrders Table : it contains the order_id user_id & quantity etc. User Table : it is having the list of users.

Are you clear with the Relationships created by me ?

auth()->user()->with('ExtraOrders.orders')->get();

Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov I have also checked the logged In user_id & it's showing correct id, so I think the relationships are wrong though can you please have a look on my code via remote access ?

Oct
18
2 days ago
Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov ->toArray() is only for dumping the data

Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov You are right. but don't know why its coming with wrong data.

for reference.


array:3 [▼
  0 => array:7 [▼
    "id" => 1
    "email" => "[email protected]"
    "role" => "admin"
    "is_approved" => 1
    "created_at" => "2019-10-07 06:38:49"
    "updated_at" => "2019-10-07 06:38:49"
    "extra_orders" => array:1 [▶]
  ]
  1 => array:7 [▼
    "id" => 2
    "email" => "[email protected]"
    "role" => "manager"
    "is_approved" => 1
    "created_at" => "2019-10-07 06:39:39"
    "updated_at" => "2019-10-07 06:39:39"
    "extra_orders" => array:1 [▼
      0 => array:9 [▼
        "id" => 77
        "order_id" => 2
        "user_id" => 2
        "quantity" => 0
        "status" => 0
        "billing" => 0
        "created_at" => "2019-10-18 11:44:06"
        "updated_at" => "2019-10-18 11:44:06"
        "orders" => null
      ]
    ]
  ]
  2 => array:7 [▼
    "id" => 3
    "email" => "[email protected]"
    "role" => "exhibitor"
    "is_approved" => 1
    "created_at" => "2019-10-07 06:40:00"
    "updated_at" => "2019-10-07 06:40:00"
    "extra_orders" => []
  ]
]

Activity icon

Replied to How To Print All Selected Items By Logged In User

@nakov Its returning with all users data but I need only logged in user data also the orders are showing null value

Activity icon

Started a new Conversation How To Print All Selected Items By Logged In User

I have three tables :

User => [ id, email, password, timestamps ] extra_orders => [ id, user_id, order_id, quantity, status, timestamps ] orders => [id, item, image, price, timestamps ]

User Model.

public function ExtraOrders()
    {
        return $this->hasMany(ExtraOrders::class,'user_id');
    }

ExtraOrders Model.

public function user()
    {
        return $this->belongsTo(User::class, 'id');
    }

    public function orders()
    {
        return $this->belongsTo(Orders::class,'id');
    }

Orders Model.

public function ExtraOrders()
    {
        return $this->hasMany(ExtraOrders::class,'order_id');
    }

my controller code for printing ordered Items.


public function orderItems()
    {   
        $myItems = ExtraOrders::where('user_id',Auth::user()->id)->with('orders')->get();
        dd($myItems->toArray());
        return view('pages.order_items',compact('myItems'));
    }

It's returning null. Please help.

Activity icon

Replied to Eloquent Relationship Help

@nakov Sure I am creating a new thread.

Activity icon

Replied to Eloquent Relationship Help

@nakov I want to print the selected orders by logged in user with orders and extraorderslist

public function orderItems()
    {   
        $myItems = ExtraOrders::where('user_id',Auth::user()->id)->with('orders')->get();
        dd($myItems->toArray());
        return view('pages.order_items',compact('myItems'));
    }
Oct
17
3 days ago
Activity icon

Replied to Eloquent Relationship Help

@nakov Thanks it's working but I want to confirm that should I run the same foreach in a table multiple times if I want to get the ExtraOrders items

Activity icon

Replied to Eloquent Relationship Help

@nakov Thanks for the suggestion. Please find below Orders Model code

 public function ExtraOrders()
    {
        return $this->hasOne(ExtraOrders::class,'order_id');
    }
Activity icon

Replied to Eloquent Relationship Help

@nakov , Now I am fetching all the order items in one place with extra orders so that I can place the quantity and checkbox checked so that particular user. below code will fetch the whole orders item with list of orders placed.

public function orderPlace() { $orders = Orders::with(['ExtraOrders'])->get(); return view('pages.order_place',compact('orders')); }

@foreach($orders as $order) @foreach($order->ExtraOrders as $userOrder)

@endforeach

@endforeach

Getting error : Invalid argument supplied for foreach() (View: D:\xampp\htdocs\portal\resources\views\pages\order_place.blade.php)

Oct
14
6 days ago
Activity icon

Replied to Eloquent Relationship Help

@nakov can you please guide how can I access the order items object inside the extra_orders object.

User::with('extraOrders')->has('extraOrders')->get();

    @foreach($extra_orders as $order)
    <tr>
        <td>{{ $order->orders->item }}</td>
    </tr>
@endforeach
Oct
10
1 week ago
Activity icon

Replied to Eloquent Relationship Help

Thanks @nakov it works. You are a genius :)

Activity icon

Replied to Eloquent Relationship Help

@nakov Yes I have tried this one but its fetching all the users but I need only those who are having the orders along with them.

array:3 [ 0 => array:7 [ "id" => 1 "email" => "[email protected]" "is_approved" => 1 "created_at" => "2019-10-07 06:38:49" "updated_at" => "2019-10-07 06:38:49" "extra_orders" => array:1 [] ] 1 => array:7 [ "id" => 2 "email" => "[email protected]" "is_approved" => 1 "created_at" => "2019-10-07 06:39:39" "updated_at" => "2019-10-07 06:39:39" "extra_orders" => array:2 [] ] 2 => array:7 [ "id" => 3 "email" => "[email protected]" "is_approved" => 1 "created_at" => "2019-10-07 06:40:00" "updated_at" => "2019-10-07 06:40:00" "extra_orders" => [] ] ]

Oct
09
1 week ago
Activity icon

Started a new Conversation Eloquent Relationship Help

I have three tables :

  1. User => [ id, email, password, timestamps ]
  2. extra_orders => [ id, user_id, order_id, quantity, status, timestamps ]
  3. orders => [id, item, image, price, timestamps ]

User Model.

public function extraOrders() { return $this->hasMany(ExtraOrders::class); }

ExtraOrder Model.

public function user() { return $this->belongsTo(User::class, 'user_id', 'id'); }

public function order()
{
    return $this->belongsTo(Orders::class);
}

Orders Model.

public function user() { return $this->belongsTo(User::class); }

In controller I am trying to get data using below method

public function orderReceived() {

    $extra_orders = ExtraOrders::with(['user','orders'])->get();
    return view('pages.order_received',compact('extra_orders'));
}

all the data is coming but I want to merge the the user extraorders if user id is same

Please check and help.

Thanks in advance.