Recently in making a note of the project, the technology stack is as follows: Vue.js + Laravel + MongoDB first had to sigh the magic of Vue, project after last night I will be on the whole project to use the technology and trampled the pit to make a summary, today first record a front-end transfer data to the backend, Examples of Laravel received.
Front-end Ajax plug-in I did not use Vue-resource, to tell the truth, with him met the pit, so used the axios.js, very easy to use, but also smaller than Vue-resource.
Look at the front-end code (omitting the Vue logic section):
Axios.post (' Index.php/login ', { email:this.email, pass:this.pass }). Then (function (res) { Console.log (res) }). Then (function () { console.log (321) })
This.email and This.pass are the form data that the user fills out, click Login to execute this method (verify that the data format is not a problem).
See how Laravel receives these two values:
We create a guser.php model file under the App folder, which reads as follows:
<?phpnamespace app;use Mongodb;use DB; Class Guser extends MongoDB {public static function login ($email) { $mongo = db::connection (' Mongodb '); $res = $mongo->collection (' user ')->where (' email ', $email)->first (); return $res; }}
Then create a gusercontroller.php file under App/http/controllers, with the following content:
<?phpnamespace app\http\controllers; Use App\http\controllers\controller;use app\guser;use illuminate\http\request; Class Gusercontroller extends controller{ protected function login (Request $request) { $email = $request Input (' email '); $pass = $request->input (' Pass '); $res = Guser::login ($email); return $res; }}
Of course, there is no pass value here, I omitted the logic of login verification here.
Then configure it in the routing file web.php:
route::any ('/login ', ' gusercontroller@login ');