90 lines
2.3 KiB
PHP
90 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
use App\Models\Customer;
|
|
use Illuminate\Http\Request;
|
|
|
|
class CustomerController extends Controller
|
|
{
|
|
/**
|
|
* Display a listing of the resource.
|
|
*/
|
|
public function index()
|
|
{
|
|
$data = Customer::orderBy('updated_at', 'desc')->get();
|
|
return view('admin.pages.customer.customer', ['type_menu' => 'customer'], compact('data'));
|
|
}
|
|
|
|
/**
|
|
* Show the form for creating a new resource.
|
|
*/
|
|
public function create()
|
|
{
|
|
return view('admin.pages.customer.createcustomer', ['type_menu' => 'customer']);
|
|
}
|
|
|
|
/**
|
|
* Store a newly created resource in storage.
|
|
*/
|
|
public function store(Request $request)
|
|
{
|
|
// dd($request);
|
|
$validateData = $request->validate([
|
|
'nama_customer' => 'required|max:255',
|
|
'email' => 'required|',
|
|
'no_hp' => 'required|string|min:10|max:13',
|
|
'alamat' => 'required|max:255',
|
|
|
|
]);
|
|
|
|
|
|
Customer::create($validateData);
|
|
|
|
return redirect('/customer')->with('success', 'data berhasil ditambahkan');
|
|
}
|
|
|
|
/**
|
|
* Display the specified resource.
|
|
*/
|
|
public function show(Customer $customer)
|
|
{
|
|
//
|
|
}
|
|
|
|
/**
|
|
* Show the form for editing the specified resource.
|
|
*/
|
|
public function edit(string $id)
|
|
{
|
|
$data = Customer::find($id);
|
|
return view('admin.pages.customer.editcustomer', ['type_menu' => 'customer'], compact('data'));
|
|
}
|
|
|
|
/**
|
|
* Update the specified resource in storage.
|
|
*/
|
|
public function update(Request $request, string $id)
|
|
{
|
|
$user = Customer::find($id);
|
|
$validateData = $request->validate([
|
|
'nama_customer' => 'required|max:255',
|
|
'email' => 'required|email:dns',
|
|
'no_hp' => 'required|string|min:10|max:13',
|
|
'alamat' => 'required|max:255',
|
|
]);
|
|
|
|
Customer::where('id', $id)->update($validateData);
|
|
|
|
return redirect('/customer')->with('success', 'data berhasil diubah');
|
|
}
|
|
|
|
/**
|
|
* Remove the specified resource from storage.
|
|
*/
|
|
public function destroy(string $id)
|
|
{
|
|
Customer::destroy($id);
|
|
return redirect('/customer')->with('delete', 'data berhasil dihapus');
|
|
}
|
|
}
|