0

I have two Mysql tables.One is matches and other one is betsettings. i have match_id as a foreign key in betsettings table.Now how can i get betsettings information for every match_name ? i want to show every matches all betsettings information under that match name.I am using laravel

matches table:

    Schema::create('matches', function (Blueprint $table) {
        $table->increments('id');
        $table->string('match_name');
        $table->timestamps();
    });

betsettings table:

    Schema::create('betsettings', function (Blueprint $table) {
        $table->increments('id');
        $table->integer('match_id')->unsigned();
        $table->dateTime('close_time');
        $table->string('status')->default('active');
        $table->timestamps();
    });

    Schema::table('betsettings', function( $table) {
          $table->foreign('match_id')
          ->references('id')
          ->on('matches')
          ->onDelete('cascade')
          ->onUpdate('cascade');
         });
4
  • is this PHP? Is this a specific framework and/or ORM on top of PHP? Please mention it, then we know what we're dealing with. P.S. In pure SQL you'd use an INNER JOIN to accomplish this. Commented Oct 23, 2019 at 15:50
  • i am using a php based frame work named laravel.i already mention that. Commented Oct 23, 2019 at 15:54
  • Sorry I missed it right at the end of your block of text. You should add suitable tags, too then it's more obvious. I will add them for you, on this occasion. If you tag your question accurately, then there is more chance that people with the relevant skills will see it. Commented Oct 23, 2019 at 16:08
  • Anyway, what have you tried so far? What have you researched? I see no attempt to even write a query. If you tried something, please show it then we can help you fix it. Commented Oct 23, 2019 at 16:09

1 Answer 1

1

You may want to look at eloquent relationships to better understanding how laravel handle with the relationships

I assume you have models for each table, lets define a relationship between those table using models.

in Match Model

public function betsettings(){
    return $this->hasOne(BetSetting:class);
}

in BetSetting Model

public function match(){
    return $this->belongsTo(Match:class);
}

Now you can get bet settings for each match using eager loading. Here is an example

$match = Match::with("betsettings")->find($id);

$match->betsettings // gives you related bet settings
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.