irankhosravi
2 months ago

How to get count order

Posted 2 months ago by irankhosravi

Each user comes in for registration. And it will enter the referral code marketer. And the user enters the marketing code. And it's stored in the parent_id.

count

And marketers can see how many people bought their code.

Users table

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->string('first_name');
        $table->string('last_name');
        $table->string('referral_code')->nullable();
        $table->integer('parent_id')->unsigned()->nullable();
        $table->string('mobile')->unique();
        $table->string('email')->unique();
        $table->string('password');
        $table->rememberToken();
        $table->timestamps();
    });
}

Order table

public function up()
{
    Schema::create('oreders', function (Blueprint $table) {
        $table->bigIncrements('id');
        $table->bigInteger('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
        $table->bigInteger('product_id')->unsigned();
        $table->foreign('product_id')->references('id')->on('products')->onDelete('cascade');
        $table->timestamps();
    });

}

My Controller.php

public function index()
{
$orders = Order::with('user')->where(''parent_id)->count();
    return $orders;
}

I get this error.

Call to undefined method App\Order::parent_id() (View: C:\xampp\htdocs\site\bazar\resources\views\Admin\master.blade.php)

Please sign in or create an account to participate in this conversation.