jeudi 23 janvier 2020

Laravel 5.8 - in_array give me error : 'htmlspecialchars() expects parameter 1 to be string, array given'

I have a function in Controller like this :

public function convert($id) {
        $project        = ProjectMaster::findOrFail($id);
        $items          = ProjectItem::all()->where('id_project_master', $id);
        $deliveryOrder  = ProjectDeliveryOrder::where('id_project', $id)->first();
        $itemsDO        = ProjectItemDeliveryOrder::all()->where('id_deliveryorder', $deliveryOrder->id)->pluck('id_item')->toArray();

        return view('delivery-order-form-add', compact('project', 'value', 'items', 'itemsDO'));
    }

$items give me result :

{
"5": {
"id": 6,
"id_project_master": 6,
"name": "Item 1",
"qty": 2,
"cost": "1,000,000",
"totalcost": "2,000,000",
"rate": "2,000,000",
"totalrate": "4,000,000",
"created_at": "2020-01-24 03:23:25",
"updated_at": "2020-01-24 03:23:25"
},
   "6": {
       "id": 7,
       "id_project_master": 6,
       "name": "Item 2",
       "qty": 2,
       "cost": "2,500,000",
       "totalcost": "5,000,000",
       "rate": "4,000,000",
       "totalrate": "8,000,000",
       "created_at": "2020-01-24 03:23:25",
       "updated_at": "2020-01-24 03:23:25"
    }
}

and $itemsDO give me result :

[
6
]

Then I have a loop where in every loop, do validate if exist in_array($this, $array) in blade view like :

@foreach ($items as $item)
<tr>
    <td class="text-right"><input type="checkbox" class="form-check-input" name="id_item[]" value="" @if(in_array($item->id, $itemsDO)) disabled @endif></td>
</tr>
@endforeach

This validate give me an error htmlspecialchars() expects parameter 1 to be string, array given. I write wrong parameter or in_array not working on blade Laravel?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire