Category

Laravel

How to Clear Cache in Laravel Without Using Artisan Commands

When working with Laravel, caching plays a key role in improving your application’s performance by storing compiled configurations, routes, views, and other data. However, during development or after making changes, you may need to clear the cache to see your latest updates. Usually, developers use Artisan commands like php artisan cache:clear or php artisan optimize:clear. […]

Upload (restore/import) a MySQL database backup via the command prompt (CLI)

To upload (restore/import) a MySQL database backup via the command prompt (CLI), you can use the mysql command-line utility. Here’s how: You must follow these requirement You must have a MySQL backup file (e.g., backup.sql) MySQL server should be installed and running You should have credentials for the MySQL user If you are working with […]

How to add new column in laravel migration without losing data

To add a new column in a Laravel migration without losing existing data, you can create a new migration file that alters the existing table. Laravel makes this easy using the php artisan make:migration command with the --table option. Step-by-Step Guide: You can generate a new migration Replace column_name with your desired column, and your_table_name […]

imagick php extension must be installed to use this driver in Laravel

It means that your Laravel app (or a package like Intervention Image, Spatie Media Library, or Laravel Snappy) is trying to use the Imagick image processing library, but it’s not installed or enabled on your server. If you’re using Ubuntu/Debian (Linux server): For PHP 8.1+, make sure you’re installing the correct version (e.g., php8.1-imagick). If […]

Attempt to read property “id” on null in Laravel

The error message “Attempt to read property ‘id’ on null” in Laravel typically occurs when you’re trying to access the id property of an object that is null. This commonly happens when you’re expecting an object to be returned (such as a database record), but instead, null is returned. You can handle this null value […]

How to check first record in Laravel blade file

Here’s how to check the first iteration in a Blade @foreach loop: You can use Laravel’s built-in $loop variable: Explanation: {{ $loop->first ? 'active' : '' }}: Adds the active class only to the first item. aria-selected="{{ $loop->first ? 'true' : 'false' }}": Ensures accessibility for tab behavior. Let me know if you also want […]

How to convert String to Lower and Upper case in Laravel blade file

In a Laravel Blade file, you can convert a string to lowercase or uppercase using PHP functions directly in the Blade syntax. Convert to Lowercase Use the strtolower() function: Convert to Uppercase Use the strtoupper() function: Using Laravel’s Str Helper Laravel provides a Str helper, which is more flexible: Lowercase using Str::lower() Uppercase using Str::upper() […]

How to make separate route files in Laravel

In Laravel, you can create separate route files to organize your routes better. Here’s how you can do it: Step 1: Create a New Route File You can create additional route files inside the routes/ directory. For example: Admin Routes → Create routes/admin.php API Routes → Create routes/custom_api.php User Routes → Create routes/user.php Step 2: […]

Setup separate layouts for the frontend and for the admin panel in your Laravel Livewire project

1. Define Frontend & Admin Layouts in Blade Templates Ensure your resources/views/layouts folder has these two layout files: resources/views/layouts/app.blade.php (Frontend Layout) resources/views/layouts/admin-app.blade.php (Admin Layout) 2. Use Layouts in Livewire Components In Livewire components, you can specify which layout to use by updating the render method. Frontend Livewire Component Example For frontend components, use app.blade.php: public […]

Illuminate \ Contracts \ Encryption \ DecryptException The payload is invalid in laravel

The error “Illuminate \ Contracts \ Encryption \ DecryptException: The payload is invalid” in Laravel occurs when the decryption of an encrypted value fails. This can happen due to several reasons: Possible Causes & Solutions: 1. Incorrect Encryption Key (APP_KEY) Laravel uses the encryption key defined in the .env file (APP_KEY). If the key is […]