lundi 3 décembre 2018

Include a custom calculation in Laravel inside the controller

I am new to php laravel. I am building a small app which displays the user table from the DB but before sending it to the view, i want to include a custom value from another function.

The accounts table fetches the list of account from MySQL and i want to include a custom function called Status which i get from an API.

The code is:

 public function accounts()
    {
    $accounts = DB::table('accounts')
        ->where('profile_id', '=', Auth::id())
        ->get();

    foreach ($accounts as $account) {

        $account->status = getStatus($account->accno);
    }

    $data = compact('accounts');
    return view::make('transactions', ['accounts' => $data]);
}

// View

  @foreach ($accounts as $account)
  <tr>
  <td></td>
  <td></td>
    <td></td>

  </tr>
  @endforeach



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire