Laravel Fortify, Vuex。数组到字符串的转换错误。 FortifyServiceProvider.php 第 40 行。发生了什么事?
Laravel Fortify, Vuex. Array to string conversion error. FortifyServiceProvider.php line 40. What's going on?
我花了将近一整天的时间来弄清楚发生了什么。我有登录 vue 组件,需要将电子邮件和密码值发送到服务器。但是登录控制器内置于 Fortify 控制器中,所以我不知道为什么我会收到错误 500 和错误 422(我得到它们的时间不同,但不是同一时间,但它们是我唯一的结果得到我的各种实验)。我为vuex存储方法和模块创建了js文件,并在模块中使用了axios.post,在登录vue组件中使用了this.$store.dispatch。
这是代码的重要部分
Login.vue
<template>
<form>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<label>
<input type="email" v-model="email" name="email" class="form-control" placeholder="email">
</label>
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<label>
<input type="password" v-model = "password" name="password" class="form-control" placeholder="password">
</label>
</div>
<div class="row align-items-center remember">
<label>
<input type="checkbox">
</label>Remember Me
</div>
<div class="form-group">
<input type="submit" v-on:click.prevent="login" value="Login" class="btn float-right login_btn">
</div>
</form>
</template>
<script>
export default {
name: "Login",
data: () => {
return {
email: '',
password: ''
}
},
methods:{
login(){
this.$store.dispatch('users/login',{}, {email: this.email, password: this.password})
},
},
}
</script>
js/store/modules/users.js
export default {
namespaced: true,
state: {
user:{}
},
getters: {
user(state) {
return state.user
}
},
mutations: {
user(state, user) {
state.comment = user
}
},
actions:
{
login(emailData,passwordData) {
axios.post('/login',{
'email': emailData, 'password': passwordData}
).then(response => {
if (response.status === 201) {
console.log('login')
} else {
console.log(response.data)
}
}).catch(error => {
console.log('oops')
});
},
}
}
js/store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import comments from "./modules/comments";
import users from "./modules/users";
Vue.use(Vuex);
export default new Vuex.Store({
modules: {
comments,
users
}
})
js/app.js
import './bootstrap'
import Vue from 'vue'
import {router} from './routes/index'
import App from './components/App.vue';
import store from './store/index'
window.Vue = Vue
const app = new Vue({
el:'#app',
router,
store,
render: h => h(App)
});
我怀疑我的问题是对 js 语法的理解不正确,或者是将数据作为参数传递给方法 axios.post() 和 this.$store.dispatch() 所需的方式。但无论如何。我不知道该怎么办。当我使用刀片而不是 vues 时,登录操作非常容易,但是使用 vue js、vuex 我 运行 遇到了困难。
错误之一,复制自我的 mozilla 浏览器
{
"message": "Array to string conversion",
"exception": "ErrorException",
"file": "C:\xampp\htdocs\dashboard\test\social_network\app\Providers\FortifyServiceProvider.php",
"line": 40,
"trace": [
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\app\Providers\FortifyServiceProvider.php",
"line": 40,
"function": "handleError",
"class": "Illuminate\Foundation\Bootstrap\HandleExceptions",
"type": "->"
},
{
"function": "App\Providers\{closure}",
"class": "App\Providers\FortifyServiceProvider",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
"line": 85,
"function": "call_user_func"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
"line": 55,
"function": "handleRequestUsingNamedLimiter",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php",
"line": 78,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\VerifyCsrfToken",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php",
"line": 49,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\View\Middleware\ShareErrorsFromSession",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php",
"line": 121,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php",
"line": 64,
"function": "handleStatefulRequest",
"class": "Illuminate\Session\Middleware\StartSession",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Session\Middleware\StartSession",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php",
"line": 37,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php",
"line": 67,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Cookie\Middleware\EncryptCookies",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 103,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 697,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 672,
"function": "runRouteWithinStack",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 636,
"function": "runRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 625,
"function": "dispatchToRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 166,
"function": "dispatch",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 128,
"function": "Illuminate\Foundation\Http\{closure}",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TrimStrings.php",
"line": 40,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TrimStrings",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php",
"line": 27,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php",
"line": 86,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\fruitcake\laravel-cors\src\HandleCors.php",
"line": 38,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Fruitcake\Cors\HandleCors",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Http\Middleware\TrustProxies.php",
"line": 39,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Http\Middleware\TrustProxies",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 103,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 141,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 110,
"function": "sendRequestThroughRouter",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\public\index.php",
"line": 52,
"function": "handle",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
}
]
}
更新:
这是来自 FortifyServiceProvider.php
的代码
<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
RateLimiter::for('login', function (Request $request) {
return Limit::perMinute(10)->by($request->email.$request->ip());
});
RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
Fortify::loginView(function () {
return view('auth.login');
});
Fortify::registerView(function () {
return view('auth.register');
});
Fortify::twoFactorChallengeView(function () {
return view('auth.two-factor-challenge');
});
Fortify::verifyEmailView(function () {
return view('auth.verify-email');
});
}
}
长话短说;博士
将您的 login
操作更新为:
action(context, payload) {
axios.post('/login', {
email: payload.email,
password: payload.password
}
)
.... // The rest of the code.
}
或者,您可以只使用 payload
作为 axios
的数据对象:
axios.post('/login', payload)
.then(...)
.catch(...)
然后将您的 dispatch call by removing the empty
{}` 更新为第二个参数:
this.$store.dispatch('users/login', {email: this.email, password: this.password})
我很确定问题出在您的 login
操作上,包括您如何调用它以及如何使用参数。
Vuex 的一个动作将 context
作为第一个参数(带有 state
和 commit
之类的对象),然后是一个可选的第二个参数,它接受有效负载(您要传递给它的数据)。
dispatch
方法将操作的名称作为第一个参数,将可选的有效负载作为第二个参数传递给操作。
所以,基本上您是将上下文对象作为电子邮件 属性 提交,当它到达服务器时将变成一个数组,因此会出现错误。
我花了将近一整天的时间来弄清楚发生了什么。我有登录 vue 组件,需要将电子邮件和密码值发送到服务器。但是登录控制器内置于 Fortify 控制器中,所以我不知道为什么我会收到错误 500 和错误 422(我得到它们的时间不同,但不是同一时间,但它们是我唯一的结果得到我的各种实验)。我为vuex存储方法和模块创建了js文件,并在模块中使用了axios.post,在登录vue组件中使用了this.$store.dispatch。
这是代码的重要部分
Login.vue
<template>
<form>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-user"></i></span>
</div>
<label>
<input type="email" v-model="email" name="email" class="form-control" placeholder="email">
</label>
</div>
<div class="input-group form-group">
<div class="input-group-prepend">
<span class="input-group-text"><i class="fas fa-key"></i></span>
</div>
<label>
<input type="password" v-model = "password" name="password" class="form-control" placeholder="password">
</label>
</div>
<div class="row align-items-center remember">
<label>
<input type="checkbox">
</label>Remember Me
</div>
<div class="form-group">
<input type="submit" v-on:click.prevent="login" value="Login" class="btn float-right login_btn">
</div>
</form>
</template>
<script>
export default {
name: "Login",
data: () => {
return {
email: '',
password: ''
}
},
methods:{
login(){
this.$store.dispatch('users/login',{}, {email: this.email, password: this.password})
},
},
}
</script>
js/store/modules/users.js
export default {
namespaced: true,
state: {
user:{}
},
getters: {
user(state) {
return state.user
}
},
mutations: {
user(state, user) {
state.comment = user
}
},
actions:
{
login(emailData,passwordData) {
axios.post('/login',{
'email': emailData, 'password': passwordData}
).then(response => {
if (response.status === 201) {
console.log('login')
} else {
console.log(response.data)
}
}).catch(error => {
console.log('oops')
});
},
}
}
js/store/index.js
import Vue from 'vue'
import Vuex from 'vuex'
import comments from "./modules/comments";
import users from "./modules/users";
Vue.use(Vuex);
export default new Vuex.Store({
modules: {
comments,
users
}
})
js/app.js
import './bootstrap'
import Vue from 'vue'
import {router} from './routes/index'
import App from './components/App.vue';
import store from './store/index'
window.Vue = Vue
const app = new Vue({
el:'#app',
router,
store,
render: h => h(App)
});
我怀疑我的问题是对 js 语法的理解不正确,或者是将数据作为参数传递给方法 axios.post() 和 this.$store.dispatch() 所需的方式。但无论如何。我不知道该怎么办。当我使用刀片而不是 vues 时,登录操作非常容易,但是使用 vue js、vuex 我 运行 遇到了困难。
错误之一,复制自我的 mozilla 浏览器
{
"message": "Array to string conversion",
"exception": "ErrorException",
"file": "C:\xampp\htdocs\dashboard\test\social_network\app\Providers\FortifyServiceProvider.php",
"line": 40,
"trace": [
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\app\Providers\FortifyServiceProvider.php",
"line": 40,
"function": "handleError",
"class": "Illuminate\Foundation\Bootstrap\HandleExceptions",
"type": "->"
},
{
"function": "App\Providers\{closure}",
"class": "App\Providers\FortifyServiceProvider",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
"line": 85,
"function": "call_user_func"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Middleware\ThrottleRequests.php",
"line": 55,
"function": "handleRequestUsingNamedLimiter",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Routing\Middleware\ThrottleRequests",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php",
"line": 78,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\VerifyCsrfToken",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php",
"line": 49,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\View\Middleware\ShareErrorsFromSession",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php",
"line": 121,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php",
"line": 64,
"function": "handleStatefulRequest",
"class": "Illuminate\Session\Middleware\StartSession",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Session\Middleware\StartSession",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php",
"line": 37,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php",
"line": 67,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Cookie\Middleware\EncryptCookies",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 103,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 697,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 672,
"function": "runRouteWithinStack",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 636,
"function": "runRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Routing\Router.php",
"line": 625,
"function": "dispatchToRoute",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 166,
"function": "dispatch",
"class": "Illuminate\Routing\Router",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 128,
"function": "Illuminate\Foundation\Http\{closure}",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php",
"line": 21,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TrimStrings.php",
"line": 40,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TransformsRequest",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\TrimStrings",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php",
"line": 27,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\ValidatePostSize",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php",
"line": 86,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\fruitcake\laravel-cors\src\HandleCors.php",
"line": 38,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Fruitcake\Cors\HandleCors",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Http\Middleware\TrustProxies.php",
"line": 39,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 167,
"function": "handle",
"class": "Illuminate\Http\Middleware\TrustProxies",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php",
"line": 103,
"function": "Illuminate\Pipeline\{closure}",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 141,
"function": "then",
"class": "Illuminate\Pipeline\Pipeline",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php",
"line": 110,
"function": "sendRequestThroughRouter",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
},
{
"file": "C:\xampp\htdocs\dashboard\test\social_network\public\index.php",
"line": 52,
"function": "handle",
"class": "Illuminate\Foundation\Http\Kernel",
"type": "->"
}
]
}
更新:
这是来自 FortifyServiceProvider.php
的代码<?php
namespace App\Providers;
use App\Actions\Fortify\CreateNewUser;
use App\Actions\Fortify\ResetUserPassword;
use App\Actions\Fortify\UpdateUserPassword;
use App\Actions\Fortify\UpdateUserProfileInformation;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\ServiceProvider;
use Laravel\Fortify\Fortify;
class FortifyServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Fortify::createUsersUsing(CreateNewUser::class);
Fortify::updateUserProfileInformationUsing(UpdateUserProfileInformation::class);
Fortify::updateUserPasswordsUsing(UpdateUserPassword::class);
Fortify::resetUserPasswordsUsing(ResetUserPassword::class);
RateLimiter::for('login', function (Request $request) {
return Limit::perMinute(10)->by($request->email.$request->ip());
});
RateLimiter::for('two-factor', function (Request $request) {
return Limit::perMinute(5)->by($request->session()->get('login.id'));
});
Fortify::loginView(function () {
return view('auth.login');
});
Fortify::registerView(function () {
return view('auth.register');
});
Fortify::twoFactorChallengeView(function () {
return view('auth.two-factor-challenge');
});
Fortify::verifyEmailView(function () {
return view('auth.verify-email');
});
}
}
长话短说;博士
将您的 login
操作更新为:
action(context, payload) {
axios.post('/login', {
email: payload.email,
password: payload.password
}
)
.... // The rest of the code.
}
或者,您可以只使用 payload
作为 axios
的数据对象:
axios.post('/login', payload)
.then(...)
.catch(...)
然后将您的 dispatch call by removing the empty
{}` 更新为第二个参数:
this.$store.dispatch('users/login', {email: this.email, password: this.password})
我很确定问题出在您的 login
操作上,包括您如何调用它以及如何使用参数。
Vuex 的一个动作将 context
作为第一个参数(带有 state
和 commit
之类的对象),然后是一个可选的第二个参数,它接受有效负载(您要传递给它的数据)。
dispatch
方法将操作的名称作为第一个参数,将可选的有效负载作为第二个参数传递给操作。
所以,基本上您是将上下文对象作为电子邮件 属性 提交,当它到达服务器时将变成一个数组,因此会出现错误。