/ / पेजिनेशन के साथ नवीनतम पोस्ट से लिंक - PHP, लार्वेल -5

पेजिंग के साथ नवीनतम पोस्ट से लिंक करें - PHP, लार्वेल -5

मैं एक बोर्ड का निर्माण कर रहा हूं और मेरे पास सभी वर्गों की एक सूची है। और इन वर्गों में धागे हैं। अनुभागों की इस सूची में मैं थ्रेड में नवीनतम पोस्ट से लिंक करना चाहता हूं।

समस्या यह है कि मेरे पास पदों के लिए एक अंकन है।

अभी मैं पहले से ही उस धागे से लिंक कर सकता हूं जहां नवीनतम पोस्ट है ..

<a href="{{ route("get_thread", [$section->id, AppTestHelpers::lastPost($section)->thread->id]) }}">Latest Post</a>

और कस्टम विधि lastPost() है..

public static function lastPost($section)
{
$threads = $section->threads;

$thread_ids = [];
foreach($threads as $thread) {
array_push($thread_ids, $thread->id);
}

$posts = Post::whereIn("thread_id", $thread_ids)->get();

return $posts->last();
}

लेकिन मुझे नहीं पता कि अगर मैं उदाहरण के लिए पोस्ट कर रहा हूं तो मैं इसे पृष्ठ से कैसे जोड़ सकता हूं ?page=2 ..

मैं यह कैसे कर सकता हूँ? अग्रिम में धन्यवाद!

उत्तर:

जवाब के लिए 0 № 1

ठीक है, मैंने इसे अभी किया है ..

सबसे पहले मैंने एक और तरीका बनाया ..

public static function lastPostPage($thread)
{
$posts = $thread->posts;

// The pagination number you"ve set
$threadPagination = 6;

// Count number of posts in thread
$countPosts = count($posts);

// Divide the number of posts by the pagination number
$lastPageNumber = round($countPosts / $threadPagination);

return "?page=" . $lastPageNumber;
}

फिर मैंने टेम्पलेट में लिंक बदल दिया ..

<a href="{{ route("get_thread", [$section->id, AppTestHelpers::lastPost($section)->thread->id]) . AppTestHelpers::lastPostPage(AppTestHelpers::lastPost($section)->thread) }}">Latest Post</a>

इसके साथ मुझे इस तरह का एक लिंक मिलता है ..

http://example.com/board/1/1?page=3

यह सबसे साफ तरीका नहीं है, लेकिन यह काम करता है! शायद एक और तरीका है।

कोई पर laracasts मेरी मदद की।