samedi 28 novembre 2020

How to search records sorted by of least difference in laravel

I have two tables customers and providers . Both table has longitude, latitude and location column . Customer will search in providers table and will get data in order by distance.

Provider which is most closed to the provider will come first.

Models names are

Provider
Customer

Provider Migration

 public function up()
    {
        Schema::create('providers', function (Blueprint $table) {
            $table->id();
            $table->string('owner_name');
            $table->string('owner_email')->unique();
           
            $table->string('password');
            $table->string('rfc');
            $table->string('tax');
            $table->string('location');
            $table->string('longitude')->nullable();
            $table->string('latitude')->nullable();
         
            $table->boolean('status')->default(1);
            $table->timestamps();
        });
    }

Customer Migration

 Schema::create('customers', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('email');
            $table->string('phone');
            $table->string('password');
          
            $table->string('location');
            $table->string('longitude')->nullable();
            $table->string('latitude')->nullable();
            $table->boolean('status')->default(1);
            $table->timestamps();
        });

How i can write query for this situation



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire