<?php

namespace App\Http\Controllers\Admin;

use Auth;
use App\PropertyInquiry;
use Illuminate\Http\Request;
use Session;

class PropertyInquiryController extends MainAdminController
{
    public function list()
    {
        if(Auth::User()->usertype!="Admin" AND Auth::User()->usertype!="Sub_Admin")
        {
            Session::flash('flash_message', trans('words.access_denied'));
            return redirect('dashboard');
        }

        if(isset($_GET['s']))
        {
            $keyword = $_GET['s'];
            $list = PropertyInquiry::where(function($query) use ($keyword) {
                $query->where("name", "LIKE", "%$keyword%")
                      ->orWhere("email", "LIKE", "%$keyword%")
                      ->orWhere("message", "LIKE", "%$keyword%");
            })->orderBy('id','DESC')->paginate(10);

            $list->appends(\Request::only('s'))->links();
        }
        else
        {
            $list = PropertyInquiry::orderBy('id','DESC')->paginate(10);
        }

        $page_title = 'Property Inquiries';

        return view('admin.pages.property.inquiries', compact('page_title','list'));
    }
}
