DeveloperBreeze

Real-Time Customization. Development Tutorials, Guides & Insights

Unlock 3+ expert-curated real-time customization. tutorials, real-world code snippets, and modern dev strategies. From fundamentals to advanced topics, boost your real-time customization. skills on DeveloperBreeze.

Creating Dynamic Content in Laravel Based on Site Settings

Tutorial November 16, 2024
php

   namespace App\Http\Controllers;

   use Illuminate\Http\Request;

   class PageController extends Controller
   {
       public function index()
       {
           $sidebarVisible = getSetting('sidebar_visible', 'false') === 'true';
           $featuredWidget = getSetting('featured_products_widget', 'false') === 'true';

           return view('pages.index', compact('sidebarVisible', 'featuredWidget'));
       }
   }

Use the passed variables in your templates:

Creating a Configurable Pagination System in Laravel

Tutorial November 16, 2024
php

   namespace App\Http\Controllers;

   use App\Models\Post;

   class PostController extends Controller
   {
       public function index()
       {
           $paginationLimit = getSetting('pagination_limit', 10);

           $posts = Post::paginate($paginationLimit);

           return view('posts.index', compact('posts'));
       }
   }
  • If no database setting is found, the default value of 10 is used.

Using Laravel Config and Localization Based on Site Settings

Tutorial November 16, 2024
php

   <form action="{{ route('admin.settings.update') }}" method="POST">
       @csrf
       @method('PUT')

       @foreach ($settings as $setting)
           <div>
               <label for="{{ $setting->key }}">{{ ucfirst(str_replace('_', ' ', $setting->key)) }}</label>
               <input type="text" name="settings[{{ $setting->key }}]" value="{{ $setting->value }}">
           </div>
       @endforeach

       <button type="submit">Save Settings</button>
   </form>
  • Flexibility: Site settings are adjustable without changing code.
  • Localization: Dynamically adapts the app’s language based on admin-defined settings.
  • Customization: Configurations like app name, timezone, or language can be updated in real-time.