本文介绍了带有参数的laravel简单轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置axios请求,但总是缺少参数,但是不确定如何传递它,有人可以解释为什么这行不通吗?

I'm trying to set axios request but always getting missing argument, but not sure how can I pass it can someone explain why this wont work?

我的路线:(web.php)

my route: (web.php)

Route::post('/api/setSuccessMessage', 'API\SessionsController@setSuccessMessage');

我的控制器:(Controllers/API/SessionsController.php)

my controller: (Controllers/API/SessionsController.php)

class SessionsController extends Controller
{
    public static function setSuccessMessage($key, $value)
    {
        session()->put($key ,$value);
    }...

和我的vueJS axios调用(资源/资产/组件/Login.vue)

and my vueJS axios call (resources/assets/components/Login.vue)

created: function () {
            // check is user logged out
            axios.post('/api/setSuccessMessages', {message: 'message',message2: 'message2'}).then((response)=> {
                console.log(response);
            })
        },

推荐答案

使用:

 public static function setSuccessMessage(Request $request)
 {
     $key = $request->get('message');
     $value = $request->get('message2');

     session()->put($key ,$value);
 }

这篇关于带有参数的laravel简单轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 19:02