質問編集履歴
2
タイトル変更
    
        title	
    CHANGED
    
    | @@ -1,1 +1,1 @@ | |
| 1 | 
            -
             | 
| 1 | 
            +
            Laravel+vueでpostを行なった場合に422エラーが発生する
         | 
    
        body	
    CHANGED
    
    | 
            File without changes
         | 
1
コード追加
    
        title	
    CHANGED
    
    | 
            File without changes
         | 
    
        body	
    CHANGED
    
    | @@ -203,4 +203,50 @@ | |
| 203 203 | 
             
                    ];
         | 
| 204 204 | 
             
                }
         | 
| 205 205 | 
             
            }
         | 
| 206 | 
            +
            ```
         | 
| 207 | 
            +
             | 
| 208 | 
            +
            ###resources/js/store/auth.js
         | 
| 209 | 
            +
            ```
         | 
| 210 | 
            +
            const state = {
         | 
| 211 | 
            +
              user: null
         | 
| 212 | 
            +
            }
         | 
| 213 | 
            +
             | 
| 214 | 
            +
            const getters = {
         | 
| 215 | 
            +
              check: state => !! state.user,
         | 
| 216 | 
            +
              username: state => state.user ? state.user.name : ''
         | 
| 217 | 
            +
            }
         | 
| 218 | 
            +
             | 
| 219 | 
            +
            const mutations = {
         | 
| 220 | 
            +
              setUser (state, user) {
         | 
| 221 | 
            +
                state.user = user
         | 
| 222 | 
            +
              }
         | 
| 223 | 
            +
            }
         | 
| 224 | 
            +
             | 
| 225 | 
            +
            const actions = {
         | 
| 226 | 
            +
              async register (context, data) {
         | 
| 227 | 
            +
                const response = await axios.post('/api/register', data)
         | 
| 228 | 
            +
                context.commit('setUser', response.data)
         | 
| 229 | 
            +
              },
         | 
| 230 | 
            +
              async login (context, data) {
         | 
| 231 | 
            +
                const response = await axios.post('/api/login', data)
         | 
| 232 | 
            +
                context.commit('setUser', response.data)
         | 
| 233 | 
            +
              },
         | 
| 234 | 
            +
              async logout (context) {
         | 
| 235 | 
            +
                const response = await axios.post('/api/logout')
         | 
| 236 | 
            +
                context.commit('setUser', null)
         | 
| 237 | 
            +
              },
         | 
| 238 | 
            +
              async currentUser (context) {
         | 
| 239 | 
            +
                const response = await axios.get('/api/user')
         | 
| 240 | 
            +
                const user = response.data || null
         | 
| 241 | 
            +
                context.commit('setUser', user)
         | 
| 242 | 
            +
              }
         | 
| 243 | 
            +
            }
         | 
| 244 | 
            +
             | 
| 245 | 
            +
            export default {
         | 
| 246 | 
            +
              namespaced: true,
         | 
| 247 | 
            +
              state,
         | 
| 248 | 
            +
              getters,
         | 
| 249 | 
            +
              mutations,
         | 
| 250 | 
            +
              actions
         | 
| 251 | 
            +
            }
         | 
| 206 252 | 
             
            ```
         | 
