dqroktbn005028 2018-06-14 11:21
浏览 231

Laravel + Vue:在web.php / api.php上路由

I am quite a new guy on Laravel and I have started working on a project, and I would like get some advice about the good architecture to pick.

I decided to manage my front with Vue and my backend with Laravel.

What I have started to do is to capture the routes through Laravel and sent it to my Vue routes to determines which components to load etc. And I was thinking to make "api" calls though axios into my Vue.components to retrieve the data (in JSON format) from my controller in order to display them into my view.

That's still a "web" needs.

But I am also thinking to the future API I will provide.

So what is the best option to take ?

Put some Route::resource('model', 'Controller') into the web.php file, then call those routes in my Vue.components, and put the Route::resource('model','Controller') into my api.php file ?

Thank you for your answer I don't know if I am going the right way or not.

Clément.

  • 写回答

1条回答 默认 最新

  • dou29106 2018-06-14 13:52
    关注

    If you look at app\Http\Kernel.php you'll notice the distinction between the web and the api group.

    • web - process "standard" requests - they need a session, checking against a user that logged in globally in the app, processing web requests. Web UI things
    • api - process stateless API requests, will most likely always consume and return json

    I usually keep the API routes in the api.php, prefix it with a version and load the controllers from the API namespace. This makes it a little more maintainable because v1 methods can be extended by a potential v2 version

    Route::prefix('v1')->namespace('Api\V1')->group(function () {
        // ... API routes
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题