PHP code example of thejawker / laravel-interrogator

1. Go to this page and download the library: Download thejawker/laravel-interrogator 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/ */

    

thejawker / laravel-interrogator example snippets


// App/Http/Controllers/UserController.php

// GET: /users?filter[name]=john*&sort=-name
// Returns the Users where the name starts with John and is sorted DESC by name. 
public function get() {
    return interrogate(User::class)->get();
}


interrogate(User::class)
    ->defaultFilters(['email' => '*@gmail.com'])
    ->get();

interrogate(User::whereType('admin'))
    ->get();

public function get() {
    return interrogate(User::class)
        ->allowFilters(['email', 'name'])
        ->get();
}   

interrogate(User::query())
    ->request($request)
    ->allowSortBy(['email'])
    ->get();   

public function get() {
    return interrogate(User::class)
        ->defaultSortBy('-email')
        ->get();
}   

// Gets all the results from the database. 
interrogate(User::class)->get();

// Paginates the results using the Laravel paginator.
interrogate(User::class)->paginate(); 

// Gets the query on the Interrogator, you are 
// then free to work with it like expected.
interrogate(User::class)->query()->take(2); 

// Illuminate\Database\Eloquent\Builder
interrogate(User::query());

// Illuminate\Database\Eloquent\Builder
interrogate(User::whereAdmin(true));

// Illuminate\Database\Eloquent\Relations\Relation;
interrogate(User::first()->posts());

// Class contstant
interrogate(User::class);