2016-07-24 2 views
0

쿼리 작성기를 사용하여 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; 

결과

Result

데이터베이스 다이어그램

SC

나는 현재 사용자에 대한 제외 를 검색하고 싶었지만

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> 

답변

0

블로그를 많이 읽은 후 나는이 교훈을 찾을 때 유용합니다. 이 가입 (문자열 $ 테이블 문자열 $ 한 문자열 $ 연산자 = NULL 문자열이 NULL = $ 두 문자열 $ TYPE = '내부'는, BOOL $ = FALSE) $

$documentsList = DB::table('document_user')->select('documents.title', 'categories.category_type', 'users.username', 'document_user.dateReceived') 
     ->join('users', 'users.id', '=', 'document_user.sender_id') 
     ->join('documents', 'documents.id', '=', 'document_user.document_id') 
     ->join('categories', 'categories.id', '=', 'documents.category_id') 
     ->where('sender_id', '!=', Auth::id())->get(); 
관련 문제