我已按如下方式設(shè)置 api.php<?phpuse Illuminate\Http\Request;use Illuminate\Support\Facades\Route;/*|--------------------------------------------------------------------------| API Routes|--------------------------------------------------------------------------|| Here is where you can register API routes for your application. These| routes are loaded by the RouteServiceProvider within a group which| is assigned the "api" middleware group. Enjoy building your API!|*//*Route::middleware('auth:api')->get('/user', function (Request $request) { return $request->user();});*/Route::get('trip', 'TripController@getTrip');盡管我首先嘗試使用它,但我注釋掉了中間件。只是為了排除它不會(huì)以某種方式產(chǎn)生影響。在我的 TripController 中我有:<?phpnamespace App\Http\Controllers;use Illuminate\Http\Request;use App\Trips;class TripController extends Controller{ public function getTrip() { $jeekim = "JEEKIM"; dd($jeekim); return response()->json(Trips::get(), 200); }}我已經(jīng)設(shè)置了數(shù)據(jù)庫(kù)并在其中添加了一些數(shù)據(jù)進(jìn)行測(cè)試。據(jù)我現(xiàn)在了解,使用 xxx.xxx.xxx.xxx/api/trip 瀏覽器應(yīng)該打開這個(gè)?但我得到了 404:在此服務(wù)器上找不到請(qǐng)求的 URL。我在控制器和 dd 中添加了變量,只是為了看看我是否達(dá)到了控制器功能,但沒有。我確保我啟用了 a2enmod 重寫。我使用海洋水滴云服務(wù)器,而不是在本地主機(jī)上。我在 web.php 中有一個(gè)測(cè)試路線,它有效,我可以返回一個(gè)視圖。但是這個(gè) api 路由我無(wú)法工作。
2 回答

慕桂英4014372
TA貢獻(xiàn)1871條經(jīng)驗(yàn) 獲得超13個(gè)贊
在你的 apache2.conf 中確保你有AllowOverride All而不是AllowOverride none。
例子-
<Directory /var/www/gloops/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

弒天下
TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超8個(gè)贊
將.htaccess
文件從公用文件夾移動(dòng)到應(yīng)用程序根目錄,并將server.php
應(yīng)用程序根目錄中的文件重命名為index.php
.
- 2 回答
- 0 關(guān)注
- 148 瀏覽
添加回答
舉報(bào)
0/150
提交
取消