shaungbhone's avatar

$_SERVER['HTTP_HOST']

when I uncomment where('sn.domain', $domain), it give me null. What happened?

$domain = $_SERVER['HTTP_HOST'];

    $siteDetails = \Illuminate\Support\Facades\DB::table('site_names as sn')
        ->join('sites as s', 's.id', '=', 'sn.site_id')
        ->join('users as u', 's.id', '=', 'u.site_id')
        ->leftJoin('css_templates as ct', 'ct.id', '=', 's.template_id')
        ->whereIn('u.user_type', [1, 2])
        // ->where('sn.domain', $domain)
        ->select('u.site_id', 'u.id as site_admin', 'u.name', 's.*', 'ct.template_name', 'ct.css')
        ->first();

    dd($siteDetails);

0 likes
7 replies
automica's avatar

what does your $siteDetails data look like before you remove the commented line?

what does $domainreturn?

automica's avatar

@shaungbhone that only shows me the same code as in this post.

Your question here is why doesnt my query return any results.

to debug that I need to know.

  1. what dd($domain) returns;
  2. what is currently being returned by dd($siteDetails)

one you are able to provide those, then someone can help.

1 like
shaungbhone's avatar

@automica

Many resellers(with different domains) can use this application. So while loading the page, we need to know which domain/site is accessing the application. This function is checking with the domain name and get the site_id of that domain name first. If that domain name does not exist in DB, it will show the error message.

Snapey's avatar

you are not being very cooperative

your query will return null if your domain is XYZ.com and your database contains xyz.com as simple example

you need to thing about the way users might type the domain name and how you might store it. You are almost certainly going to need to apply some treatment to the name such as converting case or removing tailing slashes etc etc

1 like
shaungbhone's avatar

@snapey I am sorry if I have a mistake, I handling another developer's project. It's hard for me. Thank you for helping me.

Please or to participate in this conversation.