mbo
2 months ago
313
5
Laravel

Challenge with query: local versus server.

Posted 2 months ago by mbo

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

Please sign in or create an account to participate in this conversation.