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



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/37hQ8u7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire