| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- <?php
- namespace App\Http\Resources;
- use Illuminate\Http\Resources\Json\JsonResource;
- use App\Models\PaliText;
- class SearchResource extends JsonResource
- {
- /**
- * Transform the resource into an array.
- *
- * @param \Illuminate\Http\Request $request
- * @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
- */
- public function toArray($request)
- {
- $data = [
- "book"=>$this->book,
- "paragraph"=> $this->paragraph,
- ];
- if(isset($this->rank)){
- $data["rank"] = $this->rank;
- }
- $paliText = PaliText::where('book',$this->book)
- ->where('paragraph',$this->paragraph)
- ->first();
- if(isset($this->highlight)){
- $data["highlight"] = $this->highlight;
- }else if(isset($this->content)){
- $data["content"] = $this->content;
- }else{
- $data["content"] = $paliText->html;
- }
- if($paliText){
- $data['path'] = json_decode($paliText->path);
- if($paliText->level<100){
- $data["paliTitle"] = $paliText->toc;
- }else{
- $data["paliTitle"] = PaliText::where('book',$this->book)
- ->where('paragraph',$paliText->parent)
- ->value('toc');
- }
- }
- return $data;
- }
- }
|