DeveloperBreeze

Laravel Programming Tutorials, Guides & Best Practices

Explore 51+ expertly crafted laravel tutorials, components, and code examples. Stay productive and build faster with proven implementation strategies and design patterns from DeveloperBreeze.

Tutorial
php

Securing Laravel Applications Against Common Vulnerabilities

Generate a secure authentication system with Laravel’s breeze or sanctum:

   php artisan breeze:install

Nov 16, 2024
Read More
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

  • Share app-wide settings (e.g., theme or API limits) with all views.
  • Make user-specific preferences (e.g., notification settings) accessible to controllers and views.
  • Dynamically load data blocks like navigation menus or notifications.

We’ll cover the most effective approaches to achieve this without redundancy.

Nov 16, 2024
Read More
Tutorial
php

Using Laravel Config and Localization Based on Site Settings

Add initial settings for testing purposes.

   php artisan make:seeder SiteSettingsSeeder

Nov 16, 2024
Read More
Tutorial
php

Building a Base Controller for Reusable Data Access in Laravel

Move the file to app/Http/Controllers and make it extend Laravel’s default Controller.

Add shared functionality to the Base Controller. For example:

Nov 16, 2024
Read More