jeudi 27 avril 2017

Access query string parameters using Laravel 5

I'm trying to use an existing route within my application using Request::create(). However, when passing parameters into the method I am not able to get back the respective values, instead I am getting null whic results in me getting an empty array.

The controller method that I am trying to retrieve information from is:

public function grossReport(Request $request)
{
    $fromDate  = $request->route('fromDate');
    $toDate    = $request->route('toDate');

    $result    = LoanApplication::with('product')->with('user')->with('loanPayment')
                ->where('state', 'Active')
               ->whereBetween('created_at', [$fromDate, $toDate])->paginate(10);

    foreach ($result as $value) {
        $value->branch = (isset($value->user->branch_id)) ? Branch::find($value->user->branch_id) : '';

        $value->totalGrossBalance = $this->calculate->loanBlance($value->id);
    }


    return $result;
}

I'm trying to use the route retrieve information from the grossReport() above.

$res = Request::create('/reports/get-gross-report/2013-01-08-00-00-00/2017-04-27-23-59-59', 'GET', array(), array(), array(), $server);
$response = \Route::dispatch($res)->getContent();
return $response;

Can anyone explain to me what's causing this problem. Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire