private function getZendeskAgentId()
 {
     if (!array_key_exists($this->deliver_to, $this->zendesk_agent_ids)) {
         $zendesk_user_search = Zendesk::users()->search(['query' => $this->deliver_to]);
         if (!count($zendesk_user_search)) {
             $this->zendesk_agent_ids[$this->deliver_to] = null;
         } else {
             $this->zendesk_agent_ids[$this->deliver_to] = $zendesk_user_search->users[0]->id;
         }
     }
     return $this->zendesk_agent_ids[$this->deliver_to];
 }
 /**
  * Handle an incoming request.
  *
  * @param  Request $request
  * @param  \Closure $next
  * @return mixed
  */
 public function handle(Request $request, Closure $next)
 {
     $user = $request->user();
     if (!$user->zendesk_user_id) {
         // Search for user
         $zendesk_user_search = Zendesk::users()->search(['query' => $user->email]);
         // Assign zendesk id
         if (count($zendesk_user_search->users)) {
             $user->zendesk_user_id = $zendesk_user_search->users[0]->id;
             // Create zendesk user and assign id
         } else {
             $response = Zendesk::users()->create(['name' => $user->name, 'email' => $user->email, 'verified' => true]);
             $user->zendesk_user_id = $response->user->id;
         }
         $user->save();
     }
     return $next($request);
 }
 public function index(Request $request)
 {
     $user = $request->user();
     $tickets = Zendesk::users($user->zendesk_user_id)->tickets()->findAll();
     return response()->json($tickets);
 }
 public function index()
 {
     $tickets = Zendesk::users()->search(['query' => '*****@*****.**']);
     dd($tickets);
 }