vendredi 24 mars 2017

Type conversion in laravel

I'm looping database info and sending it to jqGrid. I'm not sure why this specific line is not working: 'Store' => $store[(int)$store_id]->name,...When manually add a integer it works. $binding['store_id'] is stored as an integer. Tanks for any help.

class ApiBindingController extends Controller
{

  public function getBindingsIndex(Request $request)
  {
    $bindings = Binding::all();
    $store = Store::all();
    $bindingsArray = [];
    foreach ($bindings as $binding)
    {
      $id = $binding['id'];
      $store_id = $binding['store_id'];

      $editRoute = route('bindings.edit', ['id' => $id]);
      $editUrl = "<a href='" . $editRoute . "'>Manage</a>";
      $fullName = $binding['first_name'] . ' ' . $binding['last_name'];
      array_push($bindingsArray, array(
          'Name' => $fullName,
          'Policy Number' => $binding['policy_number'],
          'binding Number' => $binding['binding_number'],
          'Email' => $binding['email'],
          'Store' => $store[(int)$store_id]->name, // this does not work
          'Phone Number' => $binding['phone_number'],
          'Status' => $binding['status'],
          'Manage' => $editUrl,
          'Created At' => $binding['created_at']->toDateTimeString(),
          // 'Download' => $binding['download'],
      ));
    }

    return json_encode($bindingsArray);
  }
}



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2mzbkHm
via IFTTT

Aucun commentaire:

Enregistrer un commentaire