Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mbo's avatar
Level 3

Challenge with query: local versus server.

good day,

i have an issue with an query:

  • Local it works fine
  • staging (forge on digital ocean) it doesn't.

Tests i did:

(1) this query produces


     public function getSingle_dp($slug,$type) {

        $dp = dp::where('dp_name_slug', '=', $slug)
         ->where('dp_status_id',1) 
         ->with(['services' => function($query) {
          $query->where('service_status_id', '=', '1');
        }])
         ->with('images')
        ->firstOrFail();

The following output:

Local:

    "images" => Collection {#626 ▼
      #items: array:2 [▼
        0 => Image {#631 ▼
          #connection: "mysql"
          #table: null
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:11 [▶]
          #original: array:14 [▼
            "id" => 8531
            "image_user_id" => 2661
            "image_group_id" => 2661
            "image_type" => "dp"
            "image_original_name" => "Rousant_Ligplaats.jpg"
            "image_filename" => "Rousant-Lauwerzijl-1589895639013.jpg"
             "image_status" => "active"
            "created_at" => "2019-07-08 08:51:20"
            "updated_at" => "2020-05-19 13:40:39"
            "image_oldname" => "1473739301PassantenhavenRousant_Ligplaats.jpg"
            "pivot_dp_id" => 2502
            "pivot_image_id" => 8531
            "pivot_dp_image_value" => "image"


"pivot_dp_image_value" => "image" is set.

Output Staging:

    "images" => Collection {#488 ▼
      #items: array:1 [▼
        0 => Image {#495 ▼
          #connection: "mysql"
          #table: null
          #primaryKey: "id"
          #keyType: "int"
          +incrementing: true
          #with: []
          #withCount: []
          #perPage: 15
          +exists: true
          +wasRecentlyCreated: false
          #attributes: array:10 [▶]
          #original: array:13 [▼
            "id" => 8379
            "image_user_id" => 2524
            "image_group_id" => 2524
            "image_type" => "dp"
            "image_original_name" => "lijdorp.jpg"
            "image_filename" => "1470659122blijdorp.jpg"
             "image_status" => "active"
            "created_at" => "2019-07-08 08:51:11"
            "updated_at" => "2019-07-08 08:51:11"
            "pivot_dp_id" => 2365
            "pivot_image_id" => 8379
            "pivot_dp_image_value" => null

"pivot_dp_image_value" => "image" is NOT set.

(2) This query works on local. On staging the images are empty.

     public function getSingle_dp($slug,$type) {

        $dp = dp::where('dp_name_slug', '=', $slug)
         ->where('dp_status_id',1) 
         ->with(['services' => function($query) {
          $query->where('service_status_id', '=', '1');
        }])
       ->with(['images' => function ($query) {
            $query
            ->where('image_status', 'active')
            ->where('image_type', 'dp')
            ->where('dp_image_value','image');
        }])   
        ->firstOrFail();

I set the relation like this.


public function images() {

  return $this->belongsToMany('App\Image','dp_image')->withPivot('dp_image_value');
  }


Any idea what is causing the issue? i want to be able to run the second query.

thanks in advance

1 like
5 replies
tisuchi's avatar
tisuchi
Best Answer
Level 70

@mbo

Do you have the same data locally and production? I am not so sure, but it could be one of the potential reasons that you get this empty images relationship.

3 likes
mbo's avatar
Level 3

Tisuchi, thanks for the reaction. Yes the data is the same.

1 like
mbo's avatar
Level 3

even when i run this querry:

->with(['images' => function ($query) {
            $query
            ->where('image_status', 'active')
            ->where('image_type', 'dp');
           
        }])   

the images are empty.

Can it have to do with a corrupt database? (i deleted the tables by hand en imported the new data)?

1 like
tisuchi's avatar

@mbo

Just want to make sure that you have the right data.

What you get if you dump this query? Check whether it returns the image relationship data or not.

$dp = dp::where('dp_name_slug', '=', $slug)
    ->where('dp_status_id',1) 
    ->with(['images', 'services' => function($query) {
        $query->where('service_status_id', '=', '1');
    }])->firstOrFail();

dd($dp);
2 likes
mbo's avatar
Level 3

Tisuchi,

the relation is oke.

But i double checked the database. The seems that he gets the data from somewhere else.

strange because i'm loggedin on the remote database.

Thank for the help so far. If i don't get it working i will get back to you.

1 like

Please or to participate in this conversation.