lundi 28 septembre 2015

Having trouble validating on update

this is my update function in usercontroller

public function update_user_credentials(UpdateUserRequest $request)
    { 
      $user = User::find($request->user()->id);
      if(!$user) 
      {
        return response('User not found', 404);
      }

      try
      {
        $data=Input::all();
        $user->fill($data);
        var_dump($user);
        exit;
        $user->save();

      } 
      catch(Exception $ex)
      {
        return response($ex->getMessage(),400);
        echo Success::get('message');
      } 
        return Redirect::back()->with('message','updated');   
    }

my UpdateUserRequest.php

<?php
namespace App\Http\Requests;

use App\Http\Requests\Request;

class UpdateUserRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }


    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {

            return [
                'first_name' =>'required',
                'last_name'=>'required',
                'url'=>'url',
                'password'=>'min:6|confirmed',
                'password_confirmation'=>'min:6',
                'email'=>'email|unique:users,email',            
                ];
            }

}

Each column has its own form. So updating email has its own form as does password.

When I'm updating without putting UpdateUserRequest inside my update controller, it works fine. But when I add that in for validations, nothing happens. I get a 302 error but I don't any messages.

I tried getting msgs with validator->messages but also got nothing.

Also if I put in

protected $redirect = '/'

I do get redirected. That means validation is working right?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1GduVvD
via IFTTT

Aucun commentaire:

Enregistrer un commentaire