3

When I try to send request by postman fname, lname, bio, fb_token it gives me error{"frist_name":["The frist name field is required."]

this is the code:

public function store()
{
    if(User::where('fb_id','=',\Input::get('fb_id'))->exists()) 
       {
        $user = array(
            'fb_id' => Input::get('fb_id'),
            'fb_token' => Input::get('fb_token')
        );
        if (\Auth::attempt($user)) {
            echo 'found';
        } else {
            echo 'try log in again';
        }

    }
    else {
        $validation = \Validator::make(
            Request::all(), array(
            'frist_name' => 'required|alpha',
            'last_name' => 'required|alpha',
            'fb_id' => 'required|unique:user',
            'user_name' => 'required|unique:user',
            'bio' => 'max:140',
            'fb_token' => 'required|unique:user'
        ));
        $f=Request::get('frist_name');
        if ($validation->passes()) {

            $newUser = new User();
            $newUser->user_name = Request::get('user_name');
            $newUser->frist_name = Request::get('frist_name');
            $newUser->last_name = Request::get('last_name');
            $newUser->fb_id = Request::get('fb_id');
            $newUser->fb_token = Request::get('fb_token');
            $newUser->profile_pic = Request::get('profile_pic');
            $newUser->bio = Request::get('bio');
            $newUser->save();

        } else {

            $error = $validation->messages();
            return \Response::json($error);
        } }
    }
Evan Carslake
  • 2,267
  • 15
  • 38
  • 56
Marwa M
  • 35
  • 9
  • 1
    `frist_name`? Really? – Nathan Tuggy Jun 30 '15 at 02:18
  • In the request you're validating, I bet "first_name" is spelled correctly. – Dan Getz Jun 30 '15 at 02:20
  • i corrected it ...it gets the same result :$ – Marwa M Jun 30 '15 at 02:28
  • 1
    Please update your code to the corrected code. – Elin Jun 30 '15 at 02:34
  • by the way i gess fname is not the problem because in DB it's frist_name when i send request i call it frist name it always gives me that error {"frist_name":["The frist name field is required."],"last_name":["The last name field is required."],"fb_id":["The fb id field is required."],"user_name":["The user name field is required."],"fb_token":["The fb token field is required."]} – Marwa M Jun 30 '15 at 02:50
  • @MarwaM What is the value of `Request::all()`? – patricus Jun 30 '15 at 06:48
  • @patricus any input sent to me by json ! – Marwa M Jun 30 '15 at 07:57
  • @MarwaM I know what it is supposed to be. Dump it and see what you're actually getting. `dd(Request::all());` – patricus Jun 30 '15 at 07:59
  • @patricus it gives me empty list like this [] – Marwa M Jun 30 '15 at 09:00
  • @MarwaM That means your request variables are not getting through. There is something wrong with your postman request. See if anything in [this article](http://stackoverflow.com/questions/24168759/sending-post-parameters-with-postman-doesnt-work-but-sending-get-parameters-do?rq=1) helps you. If not, you'll probably need to post screenshots of your postman request in order to get more help. – patricus Jun 30 '15 at 09:18
  • @ patricus thank u so much i solved the problem i added wrong header in postman when i removed it everything becomes ok ^^ thanks for ur effort.. – Marwa M Jul 02 '15 at 09:18
  • In L5 you can/should use `Request::input` instead of `Request::get`. http://laravel.com/docs/5.0/requests#retrieving-input – Maurice Sep 18 '15 at 14:29

0 Answers0