表单详细信息存储在数据库中,但将自动注销laravel 5.3

时间:2017-01-02 07:49:37

标签: php ajax laravel

我使用laravel 5.3创建了一个FORM来添加员工。 当我填写详细信息并提交表单时,所有数据都会插入到数据库中。 但保存值后自动注销。 我无法找到该问题的任何解决方案。请帮我解决此问题。this is ajax call result

形状validation.js

It should be responsive for all the devices.

web.php

submitHandler: function(form) {

    var loading_el = $('#AddEmp');
    setLoader(loading_el, true);
    var userLevelId = $('#AddUserLevel').find('option:selected').attr('data-id');
    var policyId = $('#AddPolicies').find('option:selected').attr('data-id');

    $.ajax({
            url:'/addEmployee',
            dataType: "json",
            type: 'POST',
            data: {
                    email: $("#AddEmail").val(),
                    password: $("#AddEmpPassword").val(),
                    confirmPassword: $("#AddEmpConfirmPassword").val(),
                    EmpNo01: $("#AddEmpNo01").val(),
                    EmpNo02: $("#AddEmpNo02").val(),
                    UserLevel:userLevelId ,                 
                    Designation:$("#Designation").val(),    
                    Policies: policyId,      
                    FirstName: $("#AddFname").val(),
                    LastName: $("#AddLname").val(),
                    telephone: $("#AddTp").val(),
                    Mobile: $("#AddMno").val(),
                    JoinDate: $("#AddJoinDate").val(),
                    dob: $("#Adddob").val()

                },

EmployeeController.php

   Route::group(['middleware'=>['admin']],function(){ // start admin routes
    Route::post('/addEmployee','web\EmployeeController@AddEmployeeDetails');
   }

Employee.php

class EmployeeController extends Controller{

private $Employee;
private $policies;
private $Role;
private $Users;
private $EmployeeLeavePolicy;

public function __construct(EmployeeRepository $Employee ,LeavePolicyRepository $policies, RoleRepository $Role, UserRepository $Users,EmployeeLeavePolicyRepository $EmployeeLeavePolicy)
{
    $this->Employee = $Employee;
    $this->policies = $policies;
    $this->Role = $Role;
    $this->Users = $Users;
    $this->EmployeeLeavePolicy = $EmployeeLeavePolicy;

}

public function AddEmployeeDetails(addEmployeeRequest $request)
{
    try
    {
       $dataUser=[    //this data save in users table
            'name'=>$request['FirstName'],
            'email'=>$request['email'],
            'user_type'=>$request['UserLevel'],
            'password' => Hash::make($request['password']),

        ];

         $responseUser=$this->Users->create($dataUser);   //this is working one
        $res=$responseUser->id;

        if($responseUser)
        {
            $dataEmployee=[
                       'email'=>$request['email'],
                       'company_id'=>1,
                       'userId'=>$res,
                       'user_level'=>$request['UserLevel'],
                       'designation'=>$request['Designation'],
                       'empNo1'=>$request['EmpNo01'],
                       'empNo2'=>$request['EmpNo02'],
                       'password' => Hash::make($request['password']),
                       'first_name'=>$request['FirstName'],
                       'last_name'=>$request['LastName'],
                       'telephone'=>$request['telephone'],
                       'mobile'=>$request['Mobile'],
                       'join_date'=>$request['JoinDate'],
                       'dob'=>$request['dob'],
                       'status'=>1,
                ];

            $responseEmployee=$this->Employee->create($dataEmployee);

            if($responseEmployee)
            {
                $employeeId=$responseEmployee->id;  //get employee id
                $leaveId=$request['Policies'];      //get leave policy id

                $dataEmpLeavePolicy=[
                    'employee_Id'=>$employeeId,
                    'leave_policy_id'=>$leaveId,
                ];

                $responseLeavePolicy=$this->EmployeeLeavePolicy->create($dataEmpLeavePolicy);


            }

        Config::post('messages.ADD_USER_SUCCESS')];
            return ['success'=>'true','message'=> 'Data Added'];
        }
        else
        {
            return ['success'=>'false', 'error'=>Config::get('messages.ADD_USER_ERROR')];
        }
    }
    catch (Exception $ex)
    {
        return ['success'=>'false', 'error'=>  $ex->getMessage()];
    }

1 个答案:

答案 0 :(得分:1)

奇怪的是它会让你退出,但不是在成功/失败时返回一个数组(因为你正在进行AJAX调用),而是用json返回一个响应。

Sub removerows() Dim wsOut As Worksheet Dim wsPrev As Worksheet Dim r As Long Dim Lastrow As Long Set wsOut = Worksheets("Output") Set wsPrev = Worksheets("Previous") Lastrow = wsOut.UsedRange(wsOut.UsedRange.Cells.Count).Row For r = 2 To Lastrow If wsOut.Cells(r, "L").Value < wsPrev.Cells(2, "L").Value And _ Application.WorksheetFunction.IsNA(wsOut.Cells(r, "M").Value) Then wsOut.Cells(r, "L").EntireRow.Delete ***** r = r -1 'Done! it will recheck the same cell after Else wsOut.Cells(r, "L").Interior.ColorIndex = 20 End If Next End Sub