0

Help me on this:

I am sending JSON data through angularjs to laravel :

My angularjs Json code like:

        $scope.addnew = {name:'',email:'',message:''};
        $scope.addnew.name=$scope.name;
        $scope.addnew.email=$scope.email;
        $scope.addnew.message=$scope.message;

          $http.post("url",$scope.addnew)
        .then(function mysuccess(response) {

           console.log(response.data);

          });

Note: I have predefined url in my file.

And I want to receive this JSON file in my laravel controller so that all data can be saved in my mysql table "contactemail" and fields of table are named as name for name, email for email and message for message of user. As I am newbie in Laravel I am not able to do this correctly.Please Help me in this.

1
  • Don't forget to mark answered with the green check mark any of your questions (like the one from an hour ago) if/when you get them answered. How does accepting an answer work? ... that's how we roll here.
    – Drew
    Commented Oct 8, 2016 at 7:18

1 Answer 1

1

You can retrieve your input at Laravel using $request->input('your_json_key').

Example basic saving data:

$post = new Post();
$post->title = $request->input('title');
$post->save();

Those above code will create new post and save it to posts table (depends on your model setup).

For more information: https://laravel.com/docs/5.3/requests#accessing-the-request

1
  • I m getting this errors: 1. QueryException in Connection.php line 761: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into contact_emails (name, email, message, updated_at, created_at) values (, , , 2016-10-08 11:26:30, 2016-10-08 11:26:30)) And 2.QLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null. My model:public $fillable = ['name','email','message'];
    – Mohammed
    Commented Oct 8, 2016 at 11:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.