<?php

namespace App\Http\Resources;
use App\Http\Resources\ModelResource;
use App\Http\Resources\CategoryResource;
use App\Http\Resources\ConsultResource;

use Illuminate\Http\Resources\Json\JsonResource;
use App\ModelDescription;
use App\Language;
use App\Product;
use App\Models;
use App\ExperienceDescription;
use Illuminate\Http\Request;



class ExperienceResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        
        $name_ar =  ExperienceDescription::where('experience_id',$this->id)->where('language_id','1')->first();
        $name_en =  ExperienceDescription::where('experience_id',$this->id)->where('language_id','2')->first();
        //return parent::toArray($request);
        $user = $this->whenLoaded('user');
        return [
            'id' => $this->id,
            
            'image_link'=> !is_null($this->image) ? asset('') .$this->image : url('').'/uploads/logo.png',
            'image' => !is_null($this->image) ? $this->image : '/uploads/logo.png',
            'name' =>$this->descriptions(currentLanguage()->id)['name'],
            'name_ar'=>$name_ar->name,
            'name_en'=>$name_en->name,
            'consult'=>new ConsultResource($user),
            
            
      ];
    }
}
