<?php

namespace App\Http\Livewire;

use Cart;
use App\Models\User;
use Livewire\Component;
use Illuminate\Http\Request;
use Livewire\WithPagination;

class UserComponent extends Component
{
    use WithPagination;

    /*
    public function store($product_id, $product_name, $product_price)
    {        
       Cart::add($product_id, $product_name, 1, $product_price)->associate('\App\Models\Product');
       session()->flash('success_message', 'Item added in Cart');
       return redirect()->route('shop.cart');
    }
    */

    public function store(Request $request)
    {
        die(var_dump($request));

        $user = new User();
        $user->name = $request->input('name');
        $user->last_name = $request->input('last_name');
        $user->age = $request->input('age');
        $user->gender = $request->input('gender');
        $user->email = $request->input('email');
        $user->save();

        return redirect()->back()->with('success', 'Usuario agregado correctamente');
    }


    public function render()
    {
        $users = User::get();
        return view('livewire.user-component', ['users' => $users]);
    }
}
