dongxili9934 2017-03-14 21:33
浏览 31
已采纳

需要帮助关于Laravel Api

I have two web Application that's work in different domaine , The first one is a Laravel web application like this

domaine1.com 

and another web application that's built also with laravel

domaine2.com

and i have on the first application a dashboard like this ( domaine1.com/dashboard) , I want to add from this dashboard for example A books to the the web Application 2 , that's have it own database and tables ...... Please can someone tell me how can i do it ? i'm kind of Newbie on laravel , i think i should Use something like API ? or Something else ?

  • 写回答

2条回答 默认 最新

  • dtbc37573 2017-03-14 21:49
    关注

    Create a route in your Application 2 routes.php to get the books for example

    Route::get('domaine2.com/books', 'BookController@getBooks');
    

    In your BookController:

     public function getBooks()
        {
            $books = Books::all();    //I assume that Books is your model
            return $books
        }
    

    Now all you have to do is call this in a function in your controller from domaine1.com application to have your books

    $books = file_get_contents('http://domaine2.com/books');
    

    To give it a try first and be sure it works try accessing http://domaine2.com/books to see if you get a json with your books.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面
  • ¥15 itunes恢复数据最后一步发生错误
  • ¥15 关于#windows#的问题:2024年5月15日的win11更新后资源管理器没有地址栏了顶部的地址栏和文件搜索都消失了
  • ¥100 H5网页如何调用微信扫一扫功能?