如果你想限制你的用戶只能做點什麼,你不應該讓他們選擇他們想要的,你必須修改你的規則。
$results = $cl->Filter('country', $config['country']['us']);
如果你想向他們發放許可,更多的國家根據它們是一級搜索,你必須添加一些更多的權限設置,如用戶級別,因此,如果他們訪問http://myapp.com/search?q=Adidas&searchableCountry=3,因爲他們可以返回一個錯誤沒有許可。
例如我的想法,尚未測試,但應該工作。
<?php
//your user data
$user = json_decode('{
"user_id" : NumberLong(1004109307),
"fullname" : "Johnny",
"email" : "[email protected]",
"phone" : "123456789",
"role" : "basic", //wich user can search US,FRANCE for country id is [1,2]
"create_time" : NumberLong(1503537866)
}', true); //retun an array
//Your country id config somewhere
$country_list = array(
'US' => 1,
'FR' => 2,
'JP' => 3,
'CN' => 4,
);
//Your config somewhere
$searchable_country_config = array(
'basic' => array(
$country_list['US'], //1
$country_list['FR'], //2
),
'premium' => array(
$country_list['JP'],
$country_list['CN'],
),
);
$searchable_request = (Input::get('searchableCountry')) ? Input::get('searchableCountry') : 1; // 2 for example
$searchable_permission = $searchable_country_config[$user['role']];
//lets check that does this user have permission on their request
if(in_array($searchable_request,$searchable_permission))
{
$results = $cl->Filter('country', $searchable_request);
} else {
return response()->json(array(
'status' => 'error',
'message' => 'You have not access for this country'
));
}
我有用戶角色(基本,高級,管理等...)。但我不知道如何將它與URL限制連接起來? – harunB10
@ harunB10查看我的更新 – vietnguyen09