쿼리 작성기를 사용하여 INNER JOIN을 수행하려고합니다. 그러나 나는 내 모든 테이블이 검색 할 때이 C에서 호출) 쿼리 \ 빌더 : (가입 \를 분명히 \ 데이터베이스에 대한 논쟁이 누락 된 인수 2.내부 결합을 사용하여 선택하는 방법?
에게 실종 말한다 : \ 사용자 \ JohnFrancis \ LaravelFrancis \ app \ Http \ Controllers \ DocumentController.php 63 행에 정의되어 있습니다.
ALIAS가 잘못되었거나 SQL 쿼리를 기반으로하고 있는지 알 수 없습니다. 아래를 참조하십시오.
SQL
SELECT D.title, C.category_type, U.username, DU.dateReceived FROM document_user DU
#1st JOIN
INNER JOIN users U ON DU.sender_id = U.id
#2nd JOIN
INNER JOIN documents D ON DU.document_id = D.id
#3rd JOIN
INNER JOIN categories C ON C.id = D.category_id;
결과
데이터베이스 다이어그램
나는 현재 사용자에 대한 제외 를 검색하고 싶었지만
public function showDocuments()
{
$documentsList = DB::table('document_user')
->select('D.title', 'C.category_type', 'U.username', 'DU.dateReceived')
->join('users AS U')->on('DU.sender_id', '=', 'U.id')
->join('documents AS D')->on('DU.document_id', '=', 'D.id')
->join('categories AS C')->on('C.id', '=', 'D.category_id')
->where('sender_id', '!=', Auth::id()->get());
return view ('document.show')->with('documentsList', $documentsList);
}
컨트롤러. 여기서 볼 수 있듯이 은 절을 추가했습니다. ->where('sender_id', '!=', Auth::id()->get());
보기
<table class = "table">
<thead>
<tr>
<th>Title</th>
<th>Category</th>
<th>Sender</th>
<th>Date Received</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach ($documentsList as $list)
<tr class = "info">
<td>{{ $list->title }}</td>
<td>{{ $list->category_type }}</td>
<td>{{ $list->username }}</td>
<td>{{ $list->dateReceived }}</td>
<td><a href = "#"><button type = "submit" class = "btn btn-info">Read</button></a></td>
</tr>
@endforeach
</tbody>
</table>
http://jpcamara.com/selecting-carefully-laravel-joins/ – ClearBoth
@ClearBoth 무엇? – Francisunoxx