this is the dump data where the I fetch all the roles
Illuminate\Database\Eloquent\Collection {#1448 ▼
#items: array:5 [▼
0 => Spatie\Permission\Models\Role {#1449 ▶}
1 => Spatie\Permission\Models\Role {#1450 ▶}
2 => Spatie\Permission\Models\Role {#1451 ▶}
3 => Spatie\Permission\Models\Role {#1452 ▶}
4 => Spatie\Permission\Models\Role {#1455 ▶}
]
}
sample item from the array
#items: array:5 [▼
0 => Spatie\Permission\Models\Role {#1449 ▼
#guarded: array:1 [▶]
#connection: "mysql"
#table: "roles"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:5 [▶]
#original: array:5 [▶]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
-permissionClass: null
}
and this is the error
Invalid argument supplied for foreach() (View: C:\wamp64\www\axiebus_v2\resources\views\livewire\user-form.blade.php)
which pointed here
@foreach($roles as $role)
<div class="form-check">
<input type="check" class="form-check-input" value="{{$role->id}}" name="roles[]" id="{{$role->name}}" >
<label class="form-check-label" for="{{$role->name}}">{{$role->names}}</label>
</div>
@endforeach