I needed to add on my website some roles from database - table role_users, columns user_id and role_id. I'm using it with this code :
$career_solutions_data = DB::select(" 
SELECT 
career_solutions.id,
career_solutions.user_id,  
career_solutions.subject, 
career_solutions.date, 
career_solutions.public, 
career_solutions.views, 
career_solutions.optional, 
career_solutions.on_offer, 
users.username, 
users.profile_picture, 
categories.category, 
categories.category_url, 
categories.color, 
career_solutions_categories.category as sub_category,
career_solutions_format.category as event_format,
career_solutions_certification.category as certification
FROM career_solutions 
INNER JOIN categories 
ON categories.id = career_solutions.topic_category_id 
INNER JOIN career_solutions_format
ON career_solutions_format.id = career_solutions.topic_format_id
INNER JOIN career_solutions_certification
ON career_solutions_certification.id = career_solutions.topic_certification_id
INNER JOIN career_solutions_categories 
ON career_solutions_categories.id = career_solutions.topic_subcategory_id 
INNER JOIN users 
ON users.id = career_solutions.user_id 
INNER JOIN privacy_settings 
ON privacy_settings.user_id = users.id 
WHERE users.deleted_at IS NULL 
AND ( 
(privacy_settings.career_solutions = 0 AND public = 1 ) 
OR (users.id IN ( 
SELECT contacts.contact_id 
FROM contacts 
WHERE contacts.user_id = $id 
) 
) 
) 
OR users.id = $id 
ORDER BY date desc limit 5000 
"); 
And my view :
@if($carer_solution_data['role'][0]['pivot']['role_id'] == 1 )
                                            <i style="font-size: 11px" class="icon-user"></i> 
                                            @else <i style="font-size: 11px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
                                            @endif
Here is the line with problems:
$temp_soluation['role'] = \App\User::select('id')->where('id', '=', $career_solution->user_id)->first()->role;
Without it, my website is loading fast and correctly.
My site is loading so so slow right now.I have over 9000+ posts on my Career Solutions and I'm thinking that is the problem. This variable $carer_solution_data['role'] is loading all the posts, and that's the problem of my website. How can I avoid this problem?
 
    