first commit
This commit is contained in:
31
app/Http/Resources/ExplainCollection.php
Normal file
31
app/Http/Resources/ExplainCollection.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class ExplainCollection extends ResourceCollection
|
||||
{
|
||||
|
||||
/**
|
||||
* 将资源集合转换成数组。
|
||||
*
|
||||
* @param \Illuminate\Http\Request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
$array = [];
|
||||
foreach ($this->collection as $key => $explain) {
|
||||
$array[$key]['id'] = $explain->id;
|
||||
$array[$key]['title'] = $explain->title;
|
||||
$array[$key]['description'] = $explain->description;
|
||||
$array[$key]['created_at'] = $explain->created_at->format('Y年m月d日');
|
||||
}
|
||||
|
||||
return [
|
||||
'hasMore' => $this->resource->hasMorePages(),
|
||||
'list' => $array,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user