app/Http/Controllers/AdminController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function store(Request $request)
    {
        $admin = Admin::Where('username',$request->username)->first();
        if($admin){
            return redirect()->route('admin.index')->with(['result'=>[0],'text'=>'มีผู้ใช้อยู่แล้ว']);
        }
        $admin = new Admin();
        $admin->firstname = $request->firstname;
        $admin->lastname = $request->lastname;
        $admin->username = $request->username;
        $admin->password =  Hash::make( $request->password);
        $admin->faction = $request->faction;
        $admin->email = $request->email;
        $admin->phone = $request->phone;
        if($admin->save()){
            $error = [1,'เพิ่มผู้ใช้สำเร็จ'];
        }else{
            $error = [0,'เกิดข้อผิดพลาดบางอย่าง โปรดติดต่อแอดมิน'];
        }
        return redirect()->route('admin.index')->with(['result'=>$error[0],'text'=>$error[1]]);
    }
public function store ( Request $ request ) { $ admin = Admin :: Where ( 'username' , $ request -> username ) -> first ( ) ; if ( $ admin ) { return redirect ( ) -> route ( 'admin.index' ) -> with ( [ 'result' => [ 0 ] , 'text' => 'มีผู้ใช้อยู่แล้ว']); } $ admin = new Admin ( ) ; $ admin -> firstname = $ request -> firstname ; $ admin -> lastname = $ request -> lastname ; $ admin -> username = $ request -> username ; $ admin -> password = Hash :: make ( $ request -> password ) ; $ admin -> faction = $ request -> faction ; $ admin -> email = $ request -> email ; $ admin -> phone = $ request -> phone ; if ( $ admin -> save ( ) ) { $ error = [ 1 , 'เพิ่มผู้ใช้สำเร็จ']; } else { $ error = [ 0 , 'เกิดข้อผิดพลาดบางอย่าง โปรดติดต่อแอดมิน']; } return redirect ( ) -> route ( 'admin.index' ) -> with ( [ 'result' => $ error [ 0 ] , 'text' => $ error [ 1 ] ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
//