<?php
namespace App\Http\Controllers\Main;
use App\Http\Controllers\Controller;
use App\Models\Category;
use App\Models\Post;
use App\Models\User;
use Illuminate\Support\Facades\Auth;
class BlogController extends Controller {
public function __invoke(User $user) {
$posts = Post::orderBy('created_at', 'desc')->paginate(2);
$categoryAll = Category::all(); // если это убрать то работает пагинация
if (Auth::check()){
$role = Auth::user()->role;
}else{
$role = 0;
}
return view('main.blog', compact('user','posts','role','categoryAll'));
}
}
$categoryAll = Category::all(); // если это убрать то работает пагинация
Illuminate\Database\Eloquent\Collection {#409 ▼
#items: array:3 [▼
0 => App\Models\Category {#410 ▼
#table: "categories"
#guarded: false
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:5 [▼
"id" => 1
"title" => "kat"
"created_at" => "2023-06-28 07:20:52"
"updated_at" => "2023-06-28 07:20:52"
"deleted_at" => null
]
#original: array:5 [▶]
#changes: []
#casts: array:1 [▶]
#classCastCache: []
#attributeCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#forceDeleting: false
}
1 => App\Models\Category {#411 ▼
#table: "categories"
#guarded: false
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:5 [▼
"id" => 2
"title" => "энергетика"
"created_at" => "2023-06-28 07:26:38"
"updated_at" => "2023-06-28 07:26:38"
"deleted_at" => null
]
#original: array:5 [▶]
#changes: []
#casts: array:1 [▶]
#classCastCache: []
#attributeCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#forceDeleting: false
}
2 => App\Models\Category {#412 ▼
#table: "categories"
#guarded: false
#connection: "mysql"
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
+preventsLazyLoading: false
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#escapeWhenCastingToString: false
#attributes: array:5 [▼
"id" => 3
"title" => "троительство"
"created_at" => "2023-06-28 07:26:45"
"updated_at" => "2023-06-28 07:26:45"
"deleted_at" => null
]
#original: array:5 [▶]
#changes: []
#casts: array:1 [▶]
#classCastCache: []
#attributeCastCache: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#hidden: []
#visible: []
#fillable: []
#forceDeleting: false
}
]
#escapeWhenCastingToString: false
}
А в конце окажется, что отрабатывает не __invoke а другой метод )))
сравните url при работающей пагинации и когда не работает.