rafaeladi's avatar

Showing each test suite details based on the id

Hi, i have been working for this project for a couple of weeks now but i cant seem to find the solution for it. So basically i want to view the details of each 'test_suite' data that i have in my DB but it always return a blank collection.

So basically this is my model

    public function testDetails($case_id)
    {
        return DB::table('test_executions as e')
                    ->select('h.name as host','e.*','b.*','c.name as case')
                    ->rightJoin('test_cases as c','e.case_id','=','c.id')
                    ->rightJoin('build_versions as b','e.build_id','=','b.id')
                    ->rightJoin('test_hosts as h','e.host_id','=','h.id')
                    ->where('c.case_id',$case_id)
                    ->get();
    }

This is my controller for it

    public function details($case_id)
    {
        $data=[
            'case'=>$this->Results->testDetails($case_id),
        ];
        dump($data);

        return view ('overview_details',['test_data'=>$data]);
    }

The route to point out to the correct id

Route::get('/overview_details/{case_id}', [ResultsController::class,'details']);

And finally this is my view page

@foreach ($test_data['case'] as $value)
<tr>
<th scope="row" class='col-3'><a href="/details">{{$value->case}}</a></th>
<td class='col-4'>{{$value->branch}}</td>
<td class='col-2'>{{$value->version}}</td>
<tr>
@endforeach

And the current results is an empty collection like this

array:1 [▼
  "case" => Illuminate\Support\Collection {#291 ▼
    #items: []
  }
]

Any help is appreciated. Thanks!

0 likes
10 replies
neilstee's avatar

@rafaeladi to quickly test things out, can you try on your model:

public function testDetails($case_id)
{
        return DB::table('test_cases as c')
					->select(''c.name as case')
                    ->where('c.case_id',$case_id)
                    ->get();
}

This is just to test you can pull something on your DB, if this still returns nulll means you don't have a record.

And if it shows the correct record, then the joining of the table is the culprit.

rafaeladi's avatar

that's the thing, i tried to use without joining tables and it works fine, when i join the table but show all the information with no filtering on a specific id, it also works fine. it is when i join tables and try to get the details from it where it gets confusing because it return and empty collection

rafaeladi's avatar

the data i gather should look like this if i dont apply the where condition

array:1 [▼
  "case" => Illuminate\Support\Collection {#291 ▼
    #items: array:1 [▼
      0 => {#300 ▼
        +"host": "PC_2"
        +"id": 4
        +"name": "capUnitHappyFlow_Up"
        +"verdict": 1
        +"comment": null
        +"duration": 6510
        +"finalconfig_id": 1
        +"case_id": 3
        +"build_id": 4
        +"host_id": 2
        +"updated_at": "2021-03-18 12:28:26"
        +"create_at": "2021-03-18 12:28:26"
        +"version": "0.1.48.16"
        +"branch": "Nightly"
        +"hash": "34"
        +"case": "PfConditioning"
      }
    ]
  }
]
a4ashraf's avatar

@rafaeladi

check your table relationship it should be left join, and btw why not you use Eloquent

try with the following


public function testDetails($case_id)
    {
        return DB::table('test_executions as e')
                    ->select('h.name as host','e.*','b.*','c.name as case')
                    ->Join('test_cases as c','e.case_id','=','c.id')
                    ->Join('build_versions as b','e.build_id','=','b.id')
                    ->Join('test_hosts as h','e.host_id','=','h.id')
                    ->where('c.case_id',$case_id)
                    ->get();
    }
1 like
rafaeladi's avatar

@a4ashraf ok i will try but if the data showed up, how do i specify which one to view? can it be done just using this or do i need other things? tbh im still learning eloquent but i am more comfortable using query builder just for now

rafaeladi's avatar

@a4ashraf this is the output if i type the caseid manually in the url

array:1 [▼
  "case" => Illuminate\Support\Collection {#291 ▼
    #items: array:1 [▼
      0 => {#300 ▼
        +"host": "PC_3"
        +"id": 3
        +"name": "capUnitHappyFlow_UpSwitch"
        +"verdict": 0
        +"comment": null
        +"duration": 3654
        +"finalconfig_id": 2
        +"case_id": 4
        +"build_id": 3
        +"host_id": 3
        +"updated_at": "2021-03-18 16:05:42"
        +"create_at": "2021-03-18 16:04:51"
        +"version": "0.1.48.2"
        +"branch": "Release"
        +"hash": "35"
        +"case": "PfConditioning2"
      }
    ]
  }
]

It already showed the right data, now its just how i am connecting this together. I tried to refer to the correct id on the button but still showing me empty collection. and weirdly the url changed automatically to this

http://127.0.0.1:8000/overview_details/%7Bid%7D

eventhough i put it like this on my code

<div class="d-grid gap-2">
                <a href="/overview_details/{id}" class="btn btn-primary mt-2 ">Test Details</a>
                </div>

do you know whats wrong here?

a4ashraf's avatar

@rafaeladi

little mistake in your code

where are you getting this id /overview_details/{id}

it should be {{$id}} if you are getting it from the controller

if you have route this overview_details

then you should use it in proper Laravel syntax

https://laravel.com/docs/8.x/routing#named-routes

Route::get('/user/{id}/profile', function ($id) {
    //
})->name('profile');

$url = route('profile', ['id' => 1]);
1 like
a4ashraf's avatar
a4ashraf
Best Answer
Level 33

@rafaeladi

here is like your code


Route::get('/overview_details/{case_id}', [ResultsController::class,'details'])->name('overview_details');

<a href="{{ route('overview_details', ['case_id' => $id]) }}" class="btn btn-primary mt-2 ">Test Details</a>
1 like
rafaeladi's avatar

thank you, it is so what i was intended for

Please or to participate in this conversation.