how to receive JSON data from angularjs into laravel


Help me on this:

幫助我:

I am sending JSON data through angularjs to laravel :

我通過angularjs將JSON數據發送到laravel:

My angularjs Json code like:

我的angularjs Json代碼如下:

        $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.

注意:我的文件中有預定義的URL。

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.

我希望在我的laravel控制器中接收這個JSON文件,以便所有數據都可以保存在我的mysql表“contactemail”中,並且表的字段被命名為名稱的名稱,電子郵件的電子郵件和用戶消息的消息。因為我是Laravel的新手,所以我無法正確地做到這一點。請幫助我。

1 个解决方案

#1


1  

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

您可以使用$ request-> input('your_json_key')在Laravel中檢索輸入。

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

有關更多信息,請訪問:https://laravel.com/docs/5.3/requests#accessing-the-request


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
  © 2014-2022 ITdaan.com 联系我们: