Forum

Guides

How To Structure Database

so I have a question that's needs urgent attention

I have a project at hand I was asked to create an exchange platform (escrow) where a user can post and offer regarding the location they are coming from and where they are going to. interested user can filter this offer by there locations

it's works like this a user post an offer the user select location from & to

then those in search can filter offer by location from & to

how can I structure this kind of table

kikter
0
1
344
Haz
Moderator

Hello,

Welcome to the Codecourse forum!

I'm not quite understanding your post, but I recommend having a good read of the Laravel documentation. It might also be a good idea to show what you have tried and share some code.

https://laravel.com/docs/9.x/eloquent-relationships

https://laravel.com/docs/9.x/queries

There is a whole course on relationships from Codecourse, as well as one for filtering.

https://codecourse.com/courses/eloquent-by-example

https://codecourse.com/courses/filtering-in-laravel

Taking a stab in the dark, I am guessing you'd want to do set something like this up:

locations migration

        Schema::create('locations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id');
            $table->string('from');
            $table->string('to');
            $table->timestamps();
        });

User model

    public function locations()
    {
        return $this->hasMany(Location::class);
    }

You can then build up a query to filter using these columns.

Without a more detailed explanation and code samples, it's really hard to understand what you want to help you further. These should point you in the right direction to get you started.

UPDATE: Reading your post again, you may want to have the relationship on your Offer model instead. Ideally, if users have locations too, you can setup a polymorphic relationship.