<?php

namespace App\Http\Controllers\Backend;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Customer;
use Intervention\Image\Facades\Image;
use Carbon\Carbon;

class CustomerController extends Controller
{
     public function AllCustomer(){

        $customer = Customer::latest()->get();
        return view('backend.customer.all_customer',compact('customer'));

    } // End Method

    public function AddCustomer(){
        return view('backend.customer.add_customer');

   } // End Method


    public function StoreCustomer(Request $request){

       Customer::insert([

           'name' => $request->name,
           'email' => $request->email,
           'phone' => $request->phone,
           'address' => $request->address,
           'zip_code' => $request->zip_code,
           'city' => $request->city,
           'info' => $request->info,
           'created_at' => Carbon::now(),

       ]);


       return redirect()->route('all.customer');
   } // End Method

   public function EditCustomer($id){

    $customer = Customer::findOrFail($id);
    return view('backend.customer.edit_customer',compact('customer'));

} // End Method


 public function UpdateCustomer(Request $request){

    $customer_id = $request->id;


        Customer::findOrFail($customer_id)->update([

        'name' => $request->name,
        'email' => $request->email,
        'phone' => $request->phone,
        'address' => $request->address,
        'zip_code' => $request->zip_code,
        'city' => $request->city,
        'info' => $request->info,
         'created_at' => Carbon::now(),

    ]);


    return redirect()->route('all.customer');



} // End Method


public function DeleteCustomer($id){

    Customer::findOrFail($id)->delete();

    return redirect()->back();

} // End Method


}
