lundi 26 octobre 2015

Laravel create not accepting all input array

I'm creating an Add-User function in my website (Laravel 5.1), in which an admin account can create an account using an email, and the password will be sent to that email. The form in the Add-User view asks for the name, email, permission level, and description. The create function supposed to accept a request from that wiew, generate a password, add the password and the creator's ID into the request, create a DB entry based on the request, then send an email to that address. I'm currently stuck at creating the DB based on the request. Here is my function :

public function create(Request $request)
    {
        //generate password
        $pass = str_random(10);
        $passcrypt = bcrypt($pass);
        $email = $request->input('email');

        //change the fillable in the model
        $user = new User;
        $user->changeFillableMode("CREATE");

        //validation
        $this->validate($request,['fullname'=>'required',
                                  'email'=>'required|email',
                                  'permission_id'=>'required']);


        //adding new items to request array
        $input = $request->all();
        $input = array_add($input,'created_by_user_id',Auth::user()->user_id);
        $input = array_add($input,'password',$passcrypt);


        $user->create($input);


        //send mail
        $data['email'] = $request->input('email');
        $data['pass'] = $pass;

        Mail::queue('mail.mailbodycreate', $data, function($message) use ($email)
        {
            $message->to($email)->subject('Account info');
        });

    }

The $input already shows that the password and creator Id are already in the array, but I keep getting error that it's not in the array (since password is not nullable in my migration). can anyone help?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire