0

Im not the best in laravel but i try my best in converting sql to laravel syntax. My Problem is that i cant get an output with the inner join query i wrote.

My Query:

  $scores = DB::table('users')
    ->join('devices', 'devices.id', '=', 'users.id')
    ->select('devices.id', 'devices.devicename', 'users.name as ausgeliehen von', 'devices.created_at', 'devices.updated_at')
    ->get();

My View:

<tbody>

  @foreach ($scores as $score)
  <tr>
    <td>{{ ++$i }}</td>
    <td>{{ $score->devicename}}</td>
    <td>{{ $score->name }}</td>
    <td>{{ $score->created_at }}</td>
    <td>{{ $score->updated_at }}</td>

My Output table looks like this:

Sql query:

SELECT devices.id, devices.devicename,users.name, devices.created_at, devices.updated_at
FROM devices
INNER JOIN users ON devices.id = users.id; 

Output from sql query:

3
  • Your join conditions look suspicious to me. Why would a user ID and a device ID be related? Maybe show us your raw MySQL query, and some sample data. Commented May 18, 2018 at 7:06
  • SELECT devices.id, devices.bezeichnung,users.name, devices.created_at, devices.updated_at FROM devices INNER JOIN users ON devices.id = users.id; Commented May 18, 2018 at 7:10
  • Dont edit the original question and change your query to the working version as it is confusing for people looking for help with this issue in the future. The code should remain the broken version and then the answer that helps you will easily show how to fix it. By you fixing your original code it is hard to realise what is actually happening. Commented May 18, 2018 at 10:10

1 Answer 1

2

why you join "ausleihs" table if you don't use it?

$scores = DB::table('users')
  ->join('devices', 'devices.id', '=', 'users.id')
  ->select('devices.id', 'devices.bezeichnung', 'users.name as ausgeliehen von', 'devices.created_at', 'devices.updated_at')
  ->get();
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.