Here is my mind map. It shows that the fields in the table Match team_one and team_two refer to the Team table by the id field, i.e. connection occurs. From the name of the tables, we can conclude that the Match table is a table that displays matches, and the Team table is a list of teams.

I have this form

<form action="{{ route('match.store') }}" method="POST"> {{ csrf_field() }} <div class="uk-margin"> <input type="hidden" value="{{ Auth::id() }}" class="uk-input" name="user_id"> </div> <!-- foreach --> <div class="uk-margin"> <label class="uk-form-label">Выбор первой команды</label> <select name="team_one" class="uk-select"> @foreach($teams as $team) <option value="{{ $team->id }}">{{ $team->id }}. {{ $team->name }}</option> @endforeach </select> </div> <div class="uk-margin"> <label class="uk-form-label">Выбор второй команды</label> <select name="team_two" class="uk-select"> @foreach($teams as $team) <option value="{{ $team->id }}">{{ $team->id }}. {{ $team->name }}</option> @endforeach </select> </div> <div class="uk-margin"> <label class="uk-form-label">Сатус матча</label> <select name="status" class="uk-select"> <option value="1">Предстоящий матч</option> <option value="2">Текущий матч</option> <option value="3">Прошедший матч</option> </select> </div> <div class="uk-margin"> <label for="factor" class="uk-form-label">Factor</label> <input id="factor" type="text" class="uk-input" value="Disable" name="factor"> </div> <div class="uk-margin"> <button type="submit" class="uk-button uk-button-secondary">Добавить</button> </div> </form> 

The form adds an entry to the Match table. Now the question arises, how can I display the data from the Match table, let me remind you that in this table there is no team name (Team table), but only the numbers of these teams. I need to get data from the Match table, with data commands, i.e. for example, the team_one array contains the data of one team, and the team_two array contains the data of the second team. in one sql code, desirable.

  • A normal join is Team.id=Match.team_one OR Team.id=Match.team_two and you have exactly 2 entries at the output of the query. Each line contains data from one of the commands. Considering that fetch just creates an array, it turns out that you read 2 records in 2 different arrays and everything you wanted. in addition, you can add order by (Team.id=Match.team_two) and the first team as a result will always be in the first record, the second in the second, you will not confuse - Mike
  • And on Laravels, such a query write SELECT * FROM matches INNER JOIN teams t ON t.id = matches.team_one OR t.id = matches.team_two ORDER BY t.id = matches.team_two - Eugene
  • and for this purpose it is necessary to indicate in the question in the tags that you have a laravel, so that the question would be looked at by someone who understands it. - Mike
  • And how can I get them out, these matches? It is necessary that the match be displayed in one line, in which there is [the name of the first team, the picture of the first team, TEXT, the picture of the second team, and the name of the second team] Yevgeny
  • Well, the design on the screen is already a matter of layout. He obviously has nothing to do with the request. apparently as a block that does not allow content to be skipped to the next lines in case of overflow (as a <table> line), and there is literally $arr[0]->name .... $arr[1]->name (if you have strings in an array of course) - Mike

0