PHP code example of liam-wiltshire / laravel-jit-loader

1. Go to this page and download the library: Download liam-wiltshire/laravel-jit-loader library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

liam-wiltshire / laravel-jit-loader example snippets


$books = App\Book::with(['author', 'publisher'])->get();

$books = App\Book::all();

if ($someCondition) {
    $books->load('author', 'publisher');
}

    public function handle()
    {
        //Count the number of queries
        $querycount = 0;
        DB::listen(function ($query) use (&$querycount) {
            $querycount++;
        });

        $startTime = microtime(true);


        $staff = Staff::where('name', 'LIKE', 'E%')->orWhere('name', 'LIKE', 'P%')->get();

        /**
         * @var Staff $st
         */
        foreach ($staff as $st) {
            /**
             * @var Company $company
             */
            $company = $st->company;
            echo "\n\nName: {$st->name}\n";
            echo "Company Name: {$company->name}\n";
            foreach ($company->address as $address) {
                echo "Addresses: {$address->address_1}, ";
            }
        }

        $endTime = microtime(true);

        echo "\n\n=========================\n\n";
        echo "Queries Run: {$querycount}\n";
        echo "Execution Time: " . ($endTime - $startTime) . "\n";
        echo "Memory:" . memory_get_peak_usage(true)/1024/1024 . "MiB";
        echo "\n\n";
    }

class Address extends Model
{
    use AutoloadsRelationships;

    /**
     * @var string
     */
    protected $logChannel = 'jit-logger';

    public function company()
    {
        return $this->belongsTo(Company::class);
    }
}