Q:

add all user ids for one product

For adding to cart customer has to logg in,in cart table I have a column for user_id but in user_id column all of user_id in database add!for example for product1 all user1,user2,user3 ides add not just the one logged in
cart table:
Schema::create('cart', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('product_id');
            $table->char('user_id');
            $table->string('session_id');
            $table->string('product_name');
            $table->string('user_email');
            $table->integer('qty');
            $table->integer('product_price');

            $table->timestamps();
        });

addToCart method in controller:
public  function  addtocart(Request $request){
        $data = $request->all();
        if (empty($data['user_email'])){
            $data['user_email'] = ' ';
        }
        $user_id = User::get('id');
        if (empty($user_id)){
            $user_id = Auth::user()->id;
        }

        $session_id = Session::get('session_id');
        if (empty($session_id)){
            $session_id = Str::random(40);
            Session::put('session_id' , $session_id);
        }

        DB::table('cart')->insert(['product_id' => $data['product_id'] ,  'product_name' => $data['product_name'], 'user_id'=>$user_id,
            'product_price' => $data['product_price'], 'qty' => $data['qty'], 'user_email' => $data['user_email'] , 'session_id' => $session_id ]);

        return redirect('cart');
    }

what is the problem?

A:

You are currently requesting all the user ids by doing $user_id = User::get('id'); so if you want to set user_id as your authenticated user id you need to replace:
    $user_id = User::get('id');
    if (empty($user_id)){
        $user_id = Auth::user()->id;
    }

by:
    $user_id = Auth::user()->id;

or shorter version:
    $user_id = Auth::id();

