Skip to main content
removeu 1880 caracteres do conteúdo
Fonte Link

Fica assim o dd($categories)Consegui resolver, era meu foreach na pagina php que estava errado, alterei para

  LengthAwarePaginator {#276 ▼
  #total: 3
  #lastPage: 3
  #items: Collection {#284 ▼
    #items: array:1 [▼
      0 => Post {#285 ▼
        #fillable: array:6 [▶]
        #dates: array:2 [▶]
        #connection: "mysql"
        #table: "posts"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:10 [▼
          "id" => 55
          "title" => "Maggie"
          "slug" => "maggie-15561294631"
          "content" => "<p><span style="white-space:pre">\t</span>Lorem ipsum porttitor sodales senectus lobortis bibendum aenean nulla turpis, facilisis nunc imperdiet commodo nec ull ▶"
          "category_id" => 1
          "featured" => "uploads/posts/1556129461maggieaa.jpg"
          "deleted_at" => null
          "created_at" => "2019-04-24 18:11:03"
          "updated_at" => "2019-04@if($categories-24 18:12:36"
          "user_id" => 1
        ]
        #original: array:10 [▶]
        #changes: []
        #casts: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [▶]
        #forceDeleting: false
      }
    ]
  }
  #perPage: 1>count()>0)
  #currentPage: 1
  #path: "http://blog.test/category/1"
  #query: []
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
 @foreach($categories #options:as array:2$post) [▶]
}

O meu foreach para listar os post ficaria como usando o categories? eu tentei @foreach($categories->posts as $post) mas nao funciona, aparece Undefined property: Illuminate\Pagination\LengthAwarePaginator::e funcionou.

Fica assim o dd($categories)

  LengthAwarePaginator {#276 ▼
  #total: 3
  #lastPage: 3
  #items: Collection {#284 ▼
    #items: array:1 [▼
      0 => Post {#285 ▼
        #fillable: array:6 [▶]
        #dates: array:2 [▶]
        #connection: "mysql"
        #table: "posts"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:10 [▼
          "id" => 55
          "title" => "Maggie"
          "slug" => "maggie-15561294631"
          "content" => "<p><span style="white-space:pre">\t</span>Lorem ipsum porttitor sodales senectus lobortis bibendum aenean nulla turpis, facilisis nunc imperdiet commodo nec ull ▶"
          "category_id" => 1
          "featured" => "uploads/posts/1556129461maggieaa.jpg"
          "deleted_at" => null
          "created_at" => "2019-04-24 18:11:03"
          "updated_at" => "2019-04-24 18:12:36"
          "user_id" => 1
        ]
        #original: array:10 [▶]
        #changes: []
        #casts: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [▶]
        #forceDeleting: false
      }
    ]
  }
  #perPage: 1
  #currentPage: 1
  #path: "http://blog.test/category/1"
  #query: []
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
  #options: array:2 [▶]
}

O meu foreach para listar os post ficaria como usando o categories? eu tentei @foreach($categories->posts as $post) mas nao funciona, aparece Undefined property: Illuminate\Pagination\LengthAwarePaginator::

Consegui resolver, era meu foreach na pagina php que estava errado, alterei para

    @if($categories->count()>0)
              @foreach($categories as $post) 

e funcionou.

Fonte Link

Fica assim o dd($categories)

  LengthAwarePaginator {#276 ▼
  #total: 3
  #lastPage: 3
  #items: Collection {#284 ▼
    #items: array:1 [▼
      0 => Post {#285 ▼
        #fillable: array:6 [▶]
        #dates: array:2 [▶]
        #connection: "mysql"
        #table: "posts"
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #withCount: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:10 [▼
          "id" => 55
          "title" => "Maggie"
          "slug" => "maggie-15561294631"
          "content" => "<p><span style="white-space:pre">\t</span>Lorem ipsum porttitor sodales senectus lobortis bibendum aenean nulla turpis, facilisis nunc imperdiet commodo nec ull ▶"
          "category_id" => 1
          "featured" => "uploads/posts/1556129461maggieaa.jpg"
          "deleted_at" => null
          "created_at" => "2019-04-24 18:11:03"
          "updated_at" => "2019-04-24 18:12:36"
          "user_id" => 1
        ]
        #original: array:10 [▶]
        #changes: []
        #casts: []
        #dateFormat: null
        #appends: []
        #dispatchesEvents: []
        #observables: []
        #relations: []
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #guarded: array:1 [▶]
        #forceDeleting: false
      }
    ]
  }
  #perPage: 1
  #currentPage: 1
  #path: "http://blog.test/category/1"
  #query: []
  #fragment: null
  #pageName: "page"
  +onEachSide: 3
  #options: array:2 [▶]
}

O meu foreach para listar os post ficaria como usando o categories? eu tentei @foreach($categories->posts as $post) mas nao funciona, aparece Undefined property: Illuminate\Pagination\LengthAwarePaginator::