我在laravel中使用身份验证中间件。如果我呼叫没有middleware('auth:api')
的路由,则可以正常工作,但middleware('auth:api')
下的路由却无法工作。
我尝试更新htaccess文件并尝试了所有解决方案,但没有结果。
我的路线代码是-
Route::group(['middleware' => 'auth:api'], function(){
Route::post('unregistered', 'API\InterestController@getUnregistered');
Route::post('new-campaign-listing','API\CampaignController@new_campaign_list');
Route::post('registered-campaign-listing','API\CampaignController@registered_campaign_list');
Route::get('past-campaign-listing','API\CampaignController@past_campaign_list');
Route::get('getcampaignhistory','API\CampaignController@getCampaignhistory');
Route::post('register-for-campaign', 'API\CampaignController@register');
Route::post('top-campaign-photos', 'API\CampaignController@topPhotos');
Route::get('user-detail', 'API\PassportController@getdetails');
//update profile
Route::post('update-profile', 'API\PassportController@update_profile');
//update profile
Route::post('shared-post-data','API\CampaignController@shared_post_data');
Route::post('vip-campaigns','API\CampaignController@vip_campaigns');
Route::post('vip_client','API\CampaignController@vip_client');
Route::post('add_user_interests', 'API\InterestController@add_user_interests');
Route::get('user-interests', 'API\InterestController@user_interests');
Route::post('update-user-interests', 'API\InterestController@update_user_interest');
//polls
Route::post('polls-for-vote', 'API\PollController@pollsForVote');
Route::post('vote', 'API\PollController@vote');
Route::post('contact-us', 'API\PassportController@contactmail');
Route::get('campaignpostimage','API\PassportController@campaignpostimage');
Route::post('firebase-token', 'API\PassportController@get_token');
//notifications
Route::post('notifications', 'API\InterestController@notifcations');
Route::post('unread_notifications', 'API\InterestController@unreadNotifications');
Route::get('coupons','API\CampaignController@coupons_list');
Route::post('redeem','API\CampaignController@redeem_points');
Route::post('campaign-detail','API\CampaignController@campaign_detail');
Route::get('rewards_history','API\CampaignController@rewards_history');
});
我在passportcontroller中的功能是:
public function getDetails()
{
dd("hello");
}
我的htaccess文件代码是:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# RewriteCond %{HTTP:Authorization} ^(.*)
# RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
即使控制器中的dd也无法打印。表示API URL不起作用
答案 0 :(得分:0)
错误消息是什么? 注意:您应该将路由放入api.php
答案 1 :(得分:0)
请提供有关您如何使用API的更多信息?
如果您使用的API来自其他域(跨域),而不是面临CORS
问题,那么在这种情况下,您需要将以下package添加到laravel应用程序中
,如果您位于同一域,则可以关注 documentation。
就我而言,this git hub报告的问题解决了我的问题