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

MarcosKlender's avatar

Update query to show table in real time

Greetings!

I hope I can explain myself properly.

I have a table in my view that shows all rows in my db like this:

Query used to make this table:
$query= DB::connection('pgsql')->table('DATOS_CABECERA_OT')->get();

+-------+---------+----------------+
| form  | taller  | id_antiguedad  |
+-------+---------+----------------+
| 1     | A1      | 2020           |
| 2     | A2      | 2020           |
| 3     | A3      | 2019           |
| 4     | A1      | 2019           |
| 5     | A2      | 2019           |
| 6     | A3      | 2018           |
| 7     | B1      | 2018           |
| 8     | B2      | 2017           |
| 9     | B1      | 2017           |

Now, I need a button in my view to update the query to show specific rows using where statements, like this querys:

$query = DB::connection('pgsql')->table('DATOS_CABECERA_OT')->where('taller','A1')->get();

$query = DB::connection('pgsql')->table('DATOS_CABECERA_OT')->where('taller','B1')->where('id_antiguedad','2018')->get();

$query = DB::connection('pgsql')->table('DATOS_CABECERA_OT')->where('taller','A2')->where('id_antiguedad','2020')->get();

That button must update the rows retrieved from db and show all the new info in the same table, in real time. I also have this combo box:

<select class="form-control ml-3" id="id_antiguedad" name="id_antiguedad">
    <option value="" >ALL</option>
    <option value="2020" >2020</option>
    <option value="2019" >2019</option>
    <option value="2018" >2018</option>
    <option value="2017" >2017</option>
</select>

This combo box makes a filter to the table. I need to update the table in the view in real time. Please help!

0 likes
7 replies
drewdan's avatar

When you say realtime? Do you mean without a page refresh? If so, you will need some front end scripting like Vue, to create server calls to fetch the new data. Or you might consider using Laravel Livewire - https://laravel-livewire.com/

MarcosKlender's avatar

Oh no, sorry. I need to select an option from the combo box and then, clic in a "Update Table" button. That button must be the one that changes the query to reload the table.

drewdan's avatar

Can you show me the controller you are using which loads this blade file? I think the easiest way would be to pass some query params to this method and depending upon what you pass, will change the query that is being run

MarcosKlender's avatar

I was used an example because my controller has so many lines.

For example, I have something like this.

public function index(Request $request)
{
        $date_ini = $request->get('date_ini');
        $date_fin = $request->get('date_fin');    
        $checkbox = $request->get('check');

        $extras = ['desde' => $date_ini, 'hasta' => $date_fin];

        $local = DB::connection('pgsql')->table('DATOS_CABECERA_OT')->get();

        return view('OrdenesDeTaller')->withDetails($local)->with($extras);                
   
    return view('OrdenesDeTaller');
}

I don't have any ideas. jQuery in the view maybe?

drewdan's avatar

How come you have two return statements in your controller? The second one won't get executed

drewdan's avatar

Your select combo box. Could you wrap this in a form and submit it to this controller endpoint and the use the data you pass in to update the query for your table?

Please or to participate in this conversation.