レンダリングメソッドのライブワイヤーにコンポーネントがあります JSONリソースを呼び出してデータをマッピングし、マッピングせずにすべてのデータを返します ライブワイヤーなしで同じコードをテストし、それは機能します
public function render()
{
$allData = showReportResource::collection(Report::paginate(10));
dd($allData);
return view('livewire.all-component',compact('allData'));
}
そして私のリソースコード
class showReportResource extends JsonResource
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id'=>$this->id,
'custom'=>'custom'
];
}
}
そしてリターン
0 => App\Http\Resources\showReportResource {#1530 ▼
+resource: App\Models\Report {#1501 ▼
#fillable: array:4 [▶]
#connection: "mysql"
#table: "reports"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:7 [▼
"id" => 1
"reportable_id" => 1
"reportable_type" => "App\Models\User"
"content" => "report content is empty"
"user_id" => 11
"created_at" => "2021-09-06 11:36:08"
"updated_at" => "2021-09-06 11:36:08"
]
#original: array:7 [▶]
#changes: []
#casts: []
#classCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#guarded: array:1 [▶]
}
+with: []
+additional: []
}
問題のリソースは、リソースを解決する方法を確認せずにすべてのデータを返します