PHP code example of ed-fruty / laravel-custom-model-builder
1. Go to this page and download the library: Download ed-fruty/laravel-custom-model-builder 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/ */
ed-fruty / laravel-custom-model-builder example snippets
class ExampleBuilder extends Illuminate\Database\Eloquent\Builder
{
/**
* Add new method to builder
*
* @access public
*/
public function cacheIt()
{
$cacheTime = Config::get('someting.where.cache.time.saved');
return $this->getModel()
->remember($cacheTime)
->first();
}
}
class MyModel extends Eloquent
{
// redeclare builder by using trait
use Fruty\LaravelCustomBuilder\CustomBuilderTrait;
}
$result = MyModel::where('id', 5)->cacheIt();
bash
php artisan config:publish ed-fruty/custom-model-builder