Reputation: 404
I need to get the value from the table - privacy_settings
, column - city
, based on user_id
which is on my view {{ $user['id'] }}
from table users
, column id
.
Here is my controller :
public function findUser($role = null,$search = null,$name = null,$country = null,$city = null,$industry = null,$department = null,$function_name = null,$timeframe =null,$language_skills = null,$organization_type = null,$contact_level = null,$page = null)
{
// if($page == "")
// {
// return redirect('find-user/'.Input::get('role').'/'.Input::get('search').'/1');
// }
// return $role;
// if($page == "")
// {
// $page = 1;
// }
$data = $this->data;
$data['users'] = User::all();
$page = Input::get('page'); // Get the current page or default to 1, this is what you miss!
$perPage = 12;
$offset = ($page * $perPage) - $perPage;
$data['role'] = Input::get('role');
$search = Input::get('search');
$name = Input::get('name');
$country = Input::get('country');
$city = Input::get('city');
$industry = Input::get('industry');
$language_skills = Input::get('language_skills');
$department = Input::get('department');
$function_name = Input::get('function_name');
$company = Input::get('company');
$timeframe = Input::get('timeframe');
$organization_type = Input::get('organization_type');
$contact_level = Input::get('contact_level');
$data['search'] = $search;
// DB::enableQueryLog();
$users = User::with('country','industry','organization_type','career_path','career_path.industry','career_path.department','career_path.functions','role');
$private = DB::table('privacy_settings')->get();
How can I do that? I guess it should be something like $private = DB::table('privacy_settings')->where('id', '=', 'city')->get();
, but this doesn't working.
So, now I get the id o the user with {{ $user['id'] }}
, from table Users
, column id
.
In table privacy_settings
I have column user_id
which has id of users and city
with 2 values : 0 for public, and 1 for private. I need to get these values based on every user_id
Upvotes: 0
Views: 237
Reputation: 552
So basically, fetch the collection from column user_id where user_id = the id you passed in your blade. replace $user['id']
with that value.
$temparr = [];
$buffer = 0;
foreach($users as $user){
$arr = [];
$privacy = PrivancySetting::where('user_id', $user['id'])->first();
$city = $privacy['city'];
if($city == 0){
$buffer = 0;
$arr['id'] = $user['id'];
$arr['perm'] = $buffer;
array_push($temparr, $arr);
}else{
$buffer = 1;
$arr['id'] = $user['id'];
$arr['perm'] = $buffer;
array_push($temparr, $arr);
}
}
Pass $temparr to your view and do a loop in it to cross check and hide what you need to hide!
Upvotes: 1