<?php

namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\UserServices;


class Users extends BaseController
{
    use AuthorizesRequests, DispatchesJobs, ValidatesRequests;

    public function index()
    {
        $Users = DB::table('user_services')->paginate(1);
        // return view('admin.user_services.read', compact('user_services'));
        
        return view('Users');
    }
    public function ajaxregister()
    {
        
        $useradd = new UserServices();

        $useradd->fullname = request('fname');
        $useradd->alreadymember = request('memberyesno');
        $useradd->membershipno = request('membershipno');
        $useradd->association = request('associationname');
        $useradd->company = request('companyname');
        $useradd->companyaddress = request('companyaddress');
        $useradd->contactno = request('contact');
        $useradd->email = request('email');
        $useradd->operationtype = request('opttype');
        $useradd->product = request('product');
        $useradd->businessdetails = request('businessactivities');
        $useradd->operationarea = request('optarea');
        $useradd->cinno = request('cinno');
        $useradd->gstno = request('gstno');
        $useradd->msmeno = request('msmeno');
        $useradd->kvscno = request('kvscno');
        $useradd->otherreg = request('otherreg');
        $useradd->companytype = request('companytype');
        $useradd->turnover = request('annual');
        $useradd->client1 = request('majorclient1');
        $useradd->client2 = request('majorclient2');
        $useradd->client3 = request('majorclient3');
        $useradd->agreeterms = request('infotrue');

        $useradd->save();
        return 1;
    }

    public function userlogin(Request $request)
    {
        // $credentials = $request->only('email', 'password');

        // if (Auth::attempt($credentials)) {
        //     // Authentication passed...
        //     echo 1; exit;
        //     return redirect()->intended('dashboard');
        // }
        // else{
        //     echo 2; exit;
        // }
        
        $this->validate($request, [
            'email'   => 'required|email',
            'password' => 'required|min:6'
        ]);
        
        if (Auth::guard('userservices')->attempt(['email' => $request->email, 'password' => $request->password], $request->get('remember'))) {

            echo 3  ; exit;
            return redirect()->intended('/writer');
        }
        return back()->withInput($request->only('email', 'remember'));

    }
}
