<?php

namespace App\Http\Controllers;

use App\DataTables\AccountsDataTable;
use App\Models\Account;
use Illuminate\Http\Request;

class AccountController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index(AccountsDataTable $dataTable)
    {
        if(auth()->user()->can('show_accounts'))
        {
            
          return $dataTable->render('accounts.index');
        }
        else{
                return abort(404);

        }

    }
    public function update($id){
        $account  = Account:: findOrFail($id);
        $account->status  = !$account->status;
        $account->save();
        return $account;
    }

    public function search(Request $request)
    {
        return Account::with(['user','office'])->where('number', 'like','%'.$request->q.'%')->paginate();
    }

}
