Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use DB;
- use Datatables;
- use App\Models\M_customer;
- class Customer_controller extends Controller
- {
- public function index(){
- $title = 'List Customer';
- // $data = M_customer::orderBy('nama','asc')->get();
- $yajra = url('customer/yajra');
- return view('customer.index',compact('title','yajra'));
- }
- public function add(){
- $title = 'Add Customer';
- return view('customer.add',compact('title'));
- }
- public function store(Request $request){
- try {
- $data = $request->except(['_token','_method']);
- $data['created_at'] = date('Y-m-d H:i:s');
- $data['updated_at'] = date('Y-m-d H:i:s');
- M_customer::insert($data);
- \Session::flash('sukses','Data berhasil ditambah');
- } catch (\Exception $e) {
- \Session::flash('gagal',$e->getMessage());
- }
- return redirect()->back();
- }
- public function edit($id){
- $title = 'Edit Customer';
- $dt = M_customer::find($id);
- return view('customer.edit',compact('title','dt'));
- }
- public function update(Request $request,$id){
- try {
- $data = $request->except(['_token','_method']);
- $data['updated_at'] = date('Y-m-d H:i:s');
- M_customer::where('id',$id)->update($data);
- \Session::flash('sukses','Data berhasil diupdate');
- } catch (\Exception $e) {
- \Session::flash('gagal',$e->getMessage());
- }
- return redirect()->back();
- }
- public function delete($id){
- try {
- M_customer::where('id',$id)->delete();
- \Session::flash('sukses','Data berhasil dihapus');
- } catch (\Exception $e) {
- \Session::flash('gagal',$e->getMessage());
- }
- return redirect()->back();
- }
- public function yajra(Request $request){
- $users = M_customer::select(['*'])->get();
- return Datatables::of($users)->addColumn('action',function($e){
- $edit = url('customer/'.$e->id);
- // $dt
- return '<a href="'.$edit.'" class="btn btn-xs btn-warning"><i class="fa fa-pencil"></i></a>
- <button class="btn btn-xs btn-danger btn-hapus" href="'.$edit.'"><i class="fa fa-trash"></i></button>';
- })->make();
- }
- }
RAW Paste Data