PHP code example of zsikta / laravel-random-model

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

    

zsikta / laravel-random-model example snippets




use ZsikTa\LaravelRandomModel\RandomQueryable;

class YourModel extends Model
{
    use RandomQueryable;
}

$singleModel = YourModel::random()->first();

$modelWithRelation = YourModel::random()->with('relation_name')->first();

$model = YourModel::getRandom(); // returns an instance or null

$otherModel = YourModel::getRandomOrFail(); // returns an instance or throws exception