php - Load Laravel View with Placeholders before SQL Query Completes

764

I'm loading a view which contains results from a large SQL query which takes 10 seconds to load. It concerns users because it seems like the server is unresponsive.

Can I load the view with SQL placeholders and load the SQL results on the page after the view is loaded?

//web.php route 

Route::get('/results', '[email protected]');

//[email protected]

  public function showResults() {

    $vw = Cache::remember('vwResultsCache',3,function(){

        return $query = DB::table('vwResults')->first();
    });

    $count1 = $vw->count1;

    $count2 = $vw->count2;

    $count3 = $vw->count3;

    return view ('backend.results', compact('count1','count2','count3'));


}

 //backend.results view

     <span> Welcome to the page</span>
 <tbody>
                    <tr>

                        {{--count1--}}
                        <td>
                             {{$count1}}
                        </td>

                        {{--count2--}}
                        <td>
                             {{$count2}}
                        </td>

                        {{--count3--}}
                        <td>
                             {{$count3}}
                        </td>
                    </tr>
</tbody>

People are also looking for solutions to the problem: php - Multiple filters using xPath

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.