Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
98 views
in Technique[技术] by (71.8m points)

php - Laravel error 8 SymfonyComponentHttpKernelExceptionNotFoundHttpException

Hi I have an API in laravel 8. I am trying to access 'localhost:8000/test' and I get error "Symfony Component HttpKernel Exception NotFoundHttpException". I have the front in vue and I access axios.

Configuration axios in front 'utils/axios.js':

import axios from 'axios';

axios.defaults.baseURL = 'http://localhost:8000/';
axios.defaults.timeout = 18000;

export default axios;

Index.vue (from where the request is made):

import axios from '../utils/axios';

export default {
  name: 'PageIndex',
  methods: {
    test() {
      axios.get('test')
        .then(() => {
          console.log('ok');
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
};

File 'routes/api.php' from laravel:

<?php
use IlluminateSupportFacadesRoute;

Route::get('test', 'TestController@index');

I've tried both Route::get('test', 'TestController@index'); and Route::get('/test', 'TestController@index'); and it still doesn't work ...

I don't know what else to look at.

A greeting and thanks for the answers :)

question from:https://stackoverflow.com/questions/65864472/laravel-error-8-symfony-component-httpkernel-exception-notfoundhttpexception

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

As per the documentation, the routes defined in the routes/api.php file are reachable by prepending api before the URL, therefore, the axios.defaults.baseURL should be http://localhost:8000/api.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...