<?php

namespace Modules\Admin\Http\Controllers;

use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
use Maatwebsite\Excel\Facades\Excel;
use Carbon\Carbon;

use App\Models\User;
use App\Models\AdminDetails;
use App\Models\Companies;
use App\Models\Supliers;
use App\Models\Categories;
use App\Models\Brands;
use App\Models\Products;
use App\Models\ProductGallery;
use App\Models\Banners;
use App\Models\Services;
use App\Models\Waiters;
use App\Models\Riders;

use File;
use Mail;
use Image;
use PDF;
class RiderController extends Controller
{

    public function add_rider(Request $request)
    {
        if($request->isMethod('get')){
            return view('admin::riders.add_rider');
        }

        if($request->isMethod('post')){
            $request->validate([
                'name'   => 'required'
            ]);

            $rider = new Riders();
            $rider->name = $request->name;
            $rider->status = 'active';
            $rider->save();

            return back()->with('success', 'Rider Successfully Added');
        }
    }


public function riders(Request $request)
    { if($request->isMethod('get')){
        $riders = Riders::get();
        return view('admin::riders.riders',['riders' => $riders]);
    }

    }

    public function deactivate_rider($id){
        $rider = Riders::find($id);
        $rider->status = "inactive";
        $rider->update();
        return back()->with('success', 'Rider Deactivated');

    }
    public function activate_rider($id){
        $rider = Riders::find($id);
        $rider->status = "active";
        $rider->update();
        return back()->with('success', 'Rider Activated');

    }

    public function edit_rider($id,Request $request)
    { if($request->isMethod('get')){
        $rider_details = Riders::where('id',$id)->first();
        return view('admin::riders.edit_rider',['rider_details' => $rider_details]);
    }
    if($request->isMethod('post')){
        $request->validate([
            'name'   => 'required'
        ]);

        $rider = Riders::where('id', $id)->first();
        $rider->name = $request->name;
        $rider->update();


        return back()->with('success', 'Rider Successfully Updated');

    }

    }

    public function delete_rider($id,Request $request)
    {
        Riders::find($id)->delete();
        return back()->with('success', 'Rider Deleted');
    }

}