PHP code example of svensp / laravel-thin-repository
1. Go to this page and download the library: Download svensp/laravel-thin-repository 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/ */
svensp / laravel-thin-repository example snippets
/**
* An example Repository using the ThinRepository trait to do its work
**/
class ExampleRepository {
use ThinRepository\ThinRepository;
protected $modelClassPath = ExampleModel::class;
public function forUser($userId)
{
$this->condition(function($builder) use ($userId) {
$builder->where('user_id', $userId);
});
return $this;
}
}
$example = app(ExampleRepository::class)->forUser(5)->find();
$examples = app(ExampleRepository::class)->forUser(5)->get();