DeveloperBreeze

Continue Reading

Discover more amazing content handpicked just for you

Tutorial
php

Building a Custom Pagination System for API Responses

   public function index(Request $request)
   {
       $limit = $request->get('limit', 10);
       $cursor = $request->get('cursor');

       $query = Post::query();

       if ($cursor) {
           $query->where('id', '>', $cursor); // Fetch items after the cursor
       }

       $posts = $query->orderBy('id')->take($limit + 1)->get();

       $nextCursor = $posts->count() > $limit ? $posts->last()->id : null;

       return response()->json([
           'data' => $posts->take($limit), // Return only the requested number of items
           'meta' => [
               'limit' => $limit,
               'next_cursor' => $nextCursor,
           ],
       ]);
   }
   {
       "data": [
           { "id": 11, "title": "Post 11" },
           { "id": 12, "title": "Post 12" }
       ],
       "meta": {
           "limit": 10,
           "next_cursor": 20
       }
   }

Nov 16, 2024
Read More
Tutorial
php

Laravel Best Practices for Sharing Data Between Views and Controllers

  • Use service providers for application-wide data.
  • Use middleware for context-sensitive or user-specific data.
  • Don’t duplicate logic in multiple controllers or views.
  • Share common data globally using View::share.

Nov 16, 2024
Read More
Tutorial
php

Using Laravel Config and Localization Based on Site Settings

   php artisan make:seeder SiteSettingsSeeder

Open the seeder file and add default values:

Nov 16, 2024
Read More
Tutorial
php

Building a Base Controller for Reusable Data Access in Laravel

The Base Controller can also include methods that multiple controllers can use.

Add reusable methods to handle common tasks:

Nov 16, 2024
Read More
Code
html

Laravel CSRF-Protected Form

No preview available for this content.

Jan 26, 2024
Read More
Code
python

File Reading and Writing

No preview available for this content.

Jan 26, 2024
Read More
Code
json python

Append Data to JSON File

No preview available for this content.

Jan 26, 2024
Read More
Code
python

Read and Display Filename from a Text File

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!