Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devamit2018's avatar

query builder

select DISTINCT id,file_no,registration_date_ad,registration_date_bs from building this is my query. i have databse with table building.i want to get the specified fields data in view page in table form.

please help me with controller and blade.php

0 likes
4 replies
JavedBaloch's avatar
Level 2

You might need something like this?

Controller

public function index() {
$buildings = DB::table('building')->
select('id','file_no','registration_date_ad','registration_date_bs')->distinct()->get();
        return view('buildings.index',compact('buildings'));
}

Blade


@foreach ($buildings as $building)
    {{ $building->id }}
    {{ $building->file_no}}
    {{ $building->registration_date_ad}}
    {{ $building->registration_date_bs }}
@endforeach     

1 like
devamit2018's avatar

thanks sir,but i want to display it in table form...any idea since itcame in gathered form

devamit2018's avatar

much much thanks sir,i did it..... was stucked in it

JavedBaloch's avatar

You mean tabular form in blade?

<table>
            <thead>
                <tr>
            <th>Id</th>
            <th>File No</th>
            <th>Registration Date ad</th>
            <th>Registration Date bs</th>
        </tr>
            </thead>
            <tbody>
        @foreach ($buildings as $building)
            <tr>
                <td>{{ $building->id }}</td>
                <td>{{ $building->file_no}}</td>
                <td>{{ $building->registration_date_ad}}</td>
                <td>{{ $building->registration_date_bs }}</td>
            </tr>
        @endforeach  
            </tbody>
</table>

Please or to participate in this conversation.