Builder Pattern Method Chaining code example
Example 1: Builder Pattern Method Chaining 2
public function index(Request $request)
{
$entries = (new ReportService())
->setYear(2020)
->getTransactionReport($request->input('project'));
Example 2: Builder Pattern Method Chaining 1
class ReportService {
private $year;
public function setYear($year)
{
$this->year = $year;
return $this;
}
public function getTransactionReport(int $projectId = NULL)
{
$q = Transaction::with('project')
->with('transaction_type')
->with('income_source')
->with('currency')
->whereYear('transaction_date', $this->year)
->orderBy('transaction_date', 'desc');