jeudi 29 octobre 2015

Laravel PHP Loading Animation

I am using the Laravel framework for my PHP Webapp.

I am executing some SELECT queries which can take a few seconds to run. My Controller looks like this:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Clans;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class ClansController extends Controller
{
    public function index(){
        \DB::connection()->disableQueryLog();

        $clan = Clans::paginate(100,['id', 'clanid', 'name', 'level', 'exp', 'warwinpercent', 'warswon', 'playercount', 'score']);

        \DB::connection()->enableQueryLog();


        return view('clans.index')->with('clan', $clan);
    }



    public function order($orderby){
        \DB::connection()->disableQueryLog();

        if($orderby == "level"){
            $clan = Clans::orderBy('level', 'DESC')
            ->orderBy('exp', 'DESC')
            ->paginate(100,['id', 'clanid', 'name', 'level', 'exp', 'warwinpercent', 'warswon', 'playercount', 'score']);
        }elseif($orderby == "score"){
            $clan = Clans::orderBy('score', 'DESC')
            ->paginate(100,['id', 'clanid', 'name', 'level', 'exp', 'warwinpercent', 'warswon', 'playercount', 'score']);
        }elseif($orderby == "warwinpercent"){
            $clan = Clans::orderBy('warwinpercent', 'DESC')
            ->where('warswon', '>=', '100')
            ->paginate(100,['id', 'clanid', 'name', 'level', 'exp', 'warwinpercent', 'warswon', 'playercount', 'score']);
        }else
            $clan = Clans::paginate(100,['id', 'clanid', 'name', 'level', 'exp', 'warwinpercent', 'warswon', 'playercount', 'score']);

        \DB::connection()->enableQueryLog();

        return view('clans.index')->with('clan', $clan);
    }


    public function showclan($id){
        $clan = Clans::find($id);

        return view('clans.clan' , compact('clan'));
    }


}

What I am trying to do is while that is all running I want a loading animation to be shown to the user. When the page is loaded then I want the page to be shown.

How can I go about achieving this? I looked into JQuery and PHP stuff but they only show when the full page has already loaded (I tried them in the View).

Thanks for any help you can provide.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Wmf0m7
via IFTTT

Aucun commentaire:

Enregistrer un commentaire