Laravel Fortify, Vuex. Array to string conversion error. FortifyServiceProvider.php line 40. What’s going on?


I spent nearly whole day to figure out what’s going on. I have login vue component the email and password values need to be sent to server. But the Login controller is built in Fortify controller, so I don’t know why I’m getting error 500 and error 422 (I get them different times, not the same time, but they are the only results that I get with my various experiments). I created js file for vuex storage methods and modules and used axios.post in module and this.$store.dispatch in login vue component.

Here’s the important parts of code

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)
});

I have suspicions that my problem is in not correct understanding of js syntax, or the needed way of passing data as parameters to methods axios.post() and this.$store.dispatch(). But anyway. I don’t know what to do. When I was using blades instead of vues, it was very easy to do login action, but with vue js, vuex I ran into difficulties.

One of the errors, copied from my mozilla browser

{
  "message": "Array to string conversion",
  "exception": "ErrorException",
  "file": "C:xampphtdocsdashboardtestsocial_networkappProvidersFortifyServiceProvider.php",
  "line": 40,
  "trace": [
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkappProvidersFortifyServiceProvider.php",
      "line": 40,
      "function": "handleError",
      "class": "IlluminateFoundationBootstrapHandleExceptions",
      "type": "->"
    },
    {
      "function": "AppProviders{closure}",
      "class": "AppProvidersFortifyServiceProvider",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateRoutingMiddlewareThrottleRequests.php",
      "line": 85,
      "function": "call_user_func"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateRoutingMiddlewareThrottleRequests.php",
      "line": 55,
      "function": "handleRequestUsingNamedLimiter",
      "class": "IlluminateRoutingMiddlewareThrottleRequests",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateRoutingMiddlewareThrottleRequests",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareVerifyCsrfToken.php",
      "line": 78,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateFoundationHttpMiddlewareVerifyCsrfToken",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateViewMiddlewareShareErrorsFromSession.php",
      "line": 49,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateViewMiddlewareShareErrorsFromSession",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateSessionMiddlewareStartSession.php",
      "line": 121,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateSessionMiddlewareStartSession.php",
      "line": 64,
      "function": "handleStatefulRequest",
      "class": "IlluminateSessionMiddlewareStartSession",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateSessionMiddlewareStartSession",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateCookieMiddlewareAddQueuedCookiesToResponse.php",
      "line": 37,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateCookieMiddlewareAddQueuedCookiesToResponse",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateCookieMiddlewareEncryptCookies.php",
      "line": 67,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateCookieMiddlewareEncryptCookies",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 103,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateRoutingRouter.php",
      "line": 697,
      "function": "then",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateRoutingRouter.php",
      "line": 672,
      "function": "runRouteWithinStack",
      "class": "IlluminateRoutingRouter",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateRoutingRouter.php",
      "line": 636,
      "function": "runRoute",
      "class": "IlluminateRoutingRouter",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateRoutingRouter.php",
      "line": 625,
      "function": "dispatchToRoute",
      "class": "IlluminateRoutingRouter",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpKernel.php",
      "line": 166,
      "function": "dispatch",
      "class": "IlluminateRoutingRouter",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 128,
      "function": "IlluminateFoundationHttp{closure}",
      "class": "IlluminateFoundationHttpKernel",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareTransformsRequest.php",
      "line": 21,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareTrimStrings.php",
      "line": 40,
      "function": "handle",
      "class": "IlluminateFoundationHttpMiddlewareTransformsRequest",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateFoundationHttpMiddlewareTrimStrings",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewareValidatePostSize.php",
      "line": 27,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateFoundationHttpMiddlewareValidatePostSize",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpMiddlewarePreventRequestsDuringMaintenance.php",
      "line": 86,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateFoundationHttpMiddlewarePreventRequestsDuringMaintenance",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorfruitcakelaravel-corssrcHandleCors.php",
      "line": 38,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "FruitcakeCorsHandleCors",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateHttpMiddlewareTrustProxies.php",
      "line": 39,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 167,
      "function": "handle",
      "class": "IlluminateHttpMiddlewareTrustProxies",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminatePipelinePipeline.php",
      "line": 103,
      "function": "IlluminatePipeline{closure}",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpKernel.php",
      "line": 141,
      "function": "then",
      "class": "IlluminatePipelinePipeline",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkvendorlaravelframeworksrcIlluminateFoundationHttpKernel.php",
      "line": 110,
      "function": "sendRequestThroughRouter",
      "class": "IlluminateFoundationHttpKernel",
      "type": "->"
    },
    {
      "file": "C:xampphtdocsdashboardtestsocial_networkpublicindex.php",
      "line": 52,
      "function": "handle",
      "class": "IlluminateFoundationHttpKernel",
      "type": "->"
    }
  ]
}

Update:

Here’s the code from FortifyServiceProvider.php

<?php

namespace AppProviders;

use AppActionsFortifyCreateNewUser;
use AppActionsFortifyResetUserPassword;
use AppActionsFortifyUpdateUserPassword;
use AppActionsFortifyUpdateUserProfileInformation;
use IlluminateCacheRateLimitingLimit;
use IlluminateHttpRequest;
use IlluminateSupportFacadesRateLimiter;
use IlluminateSupportServiceProvider;
use LaravelFortifyFortify;

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');
        });
    }
}

Source: Vue – Stack Overflow

November 27, 2021
Category : News
Tags: fortify | javascript | laravel | Vue.js | vuex

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.