Answers for "Builder Pattern Method Chaining 2"

PHP
0

Builder Pattern Method Chaining 2

public function index(Request $request)
{
    $entries = (new ReportService())
        ->setYear(2020)
        ->getTransactionReport($request->input('project'));

    // ... Other code
Posted by: Guest on May-27-2021
0

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');
        // ... Other code
Posted by: Guest on May-27-2021

Browse Popular Code Answers by Language