PHP code example of permafrost-dev / laravel-helpers

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

    

permafrost-dev / laravel-helpers example snippets


$models = ModelHelper::create(MyClass::class)
    ->cached(30)
    ->orderBy('id')
    ->latest()
    ->get();

// use the model helper class
$ids = ModelHelper::create(MyClass::class)
    ->cached(60)
    ->ids();

// or use a helper function
$ids = get_cached_model_ids(MyClass::class, 60);

    //class-based
    RouteHelper::routename('web.products.show/books/123');
    
    //helper function
    routename('web.products.show/books/123');

    //get all ids for a model and cache the results; returns cached results if they exist
    function get_cached_model_ids(string $modelClass, int $ttlSeconds, int $recordLimit): array;
    
    //get all values of a column for a model and cache the results; returns cached results if they exist
    function get_cached_model_columns(string $modelClass, string $column, int $ttlSeconds, int $recordLimit): array;

    //get all values of a column for a model
    function get_model_column($modelClass, string $column, int $recordLimit): array;

    //get all ids for a model
    function get_model_ids($modelClass, int $recordLimit): array;

    //truncates text with an ellipsis, but doesn't return partially truncated words
    function str_tease(string $string, int $length, string $moreTextIndicator = '...'): string;

    //returns a relative url instead of a complete url
    function relative_route(string $name, array $parameters): string;

    //returns the value of a named route along with the provided parameters (see RouteHelper class)
    function routepath(string $routepath): string;

    //returns an array of the validated data
    function validate($fields, $rules);
    
    //returns true if the data passes validation
    function validated($fields, $rules);
    
    //creates a validator instance, accepting either array or string parameters
    function validator_create($fields, $rules);