vincej
1 week ago
205
10
Laravel

Need advice on a collection

Posted 1 week ago by vincej

Problem: I am trying to get values from a collection returned to a view. Sort of like this:

return View('workorders', compact( 'values['workorder'] ));

Sounds easy? I'm not getting there. Any suggestions ?? It should be easy.

Background Details I have a function in a controller which generates several values. I return them to another controller as an array. In turn, the other controller will dispatch them to a view. This is what I have got so far:

My Array

 return array('contractors'=>$contractors,'workorder'=>$workorder,'selected_contractor'=>$selected_contractor,'sales_order'=>$sales_order,'gross_margin'=>$gross_margin,'total_cost'=>$total_cost);

Received in the second function

$values = $this->workorder_contents($id);

Alls well so far. If I do a dd($values['workorder']); I get a nice collection out which looks like this:

Illuminate\Database\Eloquent\Collection {#819 ▼
  #items: array:1 [▼
    0 => App\Models\WorkOrder {#820 ▼
      #table: "workorders"
      #primaryKey: "id"
      #guarded: array:1 [▶]
      +timestamps: true
      #hidden: array:2 [▶]
      #dates: array:2 [▶]
      #connection: "mysql"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:28 [▼
        "id" => 8
        "contractor_id" => 67
        "order_number" => "Tru161219-53"
        "accepted" => null
        "start_date" => "Thu Feb 20, 2020"
        "wo_address" => "151 Alandale Place Calgary T3Z3L9"
        "contact" => "Donald Trump"
        "crew" => null
        "rate" => "56"
        "product" => null
        "colour" => null
        "uplift" => "12"
        "attribute" => null
        "material_qty" => 10
        "work" => "install"
        "extras" => null
        "gross_margin" => "2"
        "margin_percent" => "28"
        "project_costs" => "5390.00"
        "extras_total" => "1230.00"
        "contract" => "0.00"
        "total_contractor" => "1790.00"
        "status" => "open"
        "closed_at" => null
        "wo_comment" => null
        "created_at" => "2020-02-12 15:48:02"
        "updated_at" => "2020-02-12 15:48:02"
        "deleted_at" => null
      ]
      #original: array:28 [▶]
      #changes: []


Please sign in or create an account to participate in this conversation.