DeveloperBreeze

Related Posts

More content you might like

Tutorial
php

Securing Laravel Applications Against Common Vulnerabilities

Use Laravel’s encrypt and decrypt helpers for storing sensitive data securely:

   $encrypted = encrypt($sensitiveData);
   $decrypted = decrypt($encrypted);

Nov 16, 2024
Read More
Tutorial
php

Building a Custom Pagination System for API Responses

Modify the query to use a cursor:

   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,
           ],
       ]);
   }

Nov 16, 2024
Read More
Tutorial
php

Laravel Best Practices for Sharing Data Between Views and Controllers

Use Laravel's View::share method to make data available to all views.

Open or create a service provider like AppServiceProvider:

Nov 16, 2024
Read More
Tutorial
php

Creating a Configurable Pagination System in Laravel

   namespace App\Http\Controllers\Admin;

   use App\Models\Setting;
   use Illuminate\Http\Request;

   class SettingsController extends Controller
   {
       public function edit()
       {
           $paginationLimit = Setting::where('key', 'pagination_limit')->value('value');
           return view('admin.settings.edit', compact('paginationLimit'));
       }

       public function update(Request $request)
       {
           Setting::updateOrCreate(
               ['key' => 'pagination_limit'],
               ['value' => $request->input('pagination_limit')]
           );

           return redirect()->back()->with('success', 'Pagination limit updated successfully.');
       }
   }

Create resources/views/admin/settings/edit.blade.php:

Nov 16, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Be the first to share your thoughts!