CoderFunda
  • Home
  • About us
    • Contact Us
    • Disclaimer
    • Privacy Policy
    • About us
  • Home
  • Php
  • HTML
  • CSS
  • JavaScript
    • JavaScript
    • Jquery
    • JqueryUI
    • Stock
  • SQL
  • Vue.Js
  • Python
  • Wordpress
  • C++
    • C++
    • C
  • Laravel
    • Laravel
      • Overview
      • Namespaces
      • Middleware
      • Routing
      • Configuration
      • Application Structure
      • Installation
    • Overview
  • DBMS
    • DBMS
      • PL/SQL
      • SQLite
      • MongoDB
      • Cassandra
      • MySQL
      • Oracle
      • CouchDB
      • Neo4j
      • DB2
      • Quiz
    • Overview
  • Entertainment
    • TV Series Update
    • Movie Review
    • Movie Review
  • More
    • Vue. Js
    • Php Question
    • Php Interview Question
    • Laravel Interview Question
    • SQL Interview Question
    • IAS Interview Question
    • PCS Interview Question
    • Technology
    • Other

29 November, 2022

Easy Debouncing For Queue Jobs or Chains in your Laravel App

 Programing Coderfunda     November 29, 2022     Laravel, laravel-packages, php     No comments   

Laravel Queue Debouncer package allows any queue job or chain in your Laravel application to be debounced, meaning that no matter how many times it’s dispatched within the specified timeout window, it will only run once.

For example, imagine you dispatch a job to rebuild a cache every time a record is updated, but the job is resource intensive. Debouncing the job with a five-minute wait would ensure that the cache is only rebuilt once, five minutes after you finish making changes.

Installation

You can install this package via composer by running this command.

composer require mpbarlow/laravel-queue-debouncer

Usage

Debounced jobs can largely be treated like any other dispatched job. The debouncer takes two arguments, the actual $job you want to run, and the $wait period.

As with a regular dispatch, $job can be either a class implementing Illuminate\Foundation\Bus\Dispatchable, a chain, or a closure. $wait accepts any argument that the delay method on a dispatch accepts (i.e. a DateTimeInterface or a number of seconds).

The debouncer returns an instance of Illuminate\Foundation\Bus\PendingDispatch, meaning the debouncing process itself may be assigned to a different queue or otherwise manipulated.

Calling the debouncer

There are several ways to use the debouncer:

Dependency Injection

use App\Jobs\MyJob;
use Mpbarlow\LaravelQueueDebouncer\Debouncer;

class MyController
{
    public function doTheThing(Debouncer $debouncer)
    {
        $debouncer->debounce(new MyJob(), 30);

        // The class is also invokable:
        $debouncer(new MyJob(), 30);
    }
}

Facade

use App\Jobs\MyJob;
use Mpbarlow\LaravelQueueDebouncer\Facade\Debouncer;

Debouncer::debounce(new MyJob, 30);

Helper function

use App\Jobs\MyJob;

debounce(new MyJob(), 30);

When monitoring the queue, you will see an entry for the package’s internal dispatcher each time the debounced job is queued, but the job itself will only run once when the final wait time has expired.

For example, assuming the following code was run at exactly 9 am:

class MyJob
{
    use Dispatchable;

    public function handle()
    {
        echo “Hello!\n”;
    }
}

$job = new MyJob();

debounce($job, now()->addSeconds(5));
sleep(3);

debounce($job, now()->addSeconds(5));
sleep(3);

debounce($job, now()->addSeconds(5));

you should expect the following activity on your queue:

[2020-03-11 09:00:05][vHmqrBYeLtK3Lbiq5TsTZxBo2igaCZHC] Processing: Closure (DispatcherFactory.php:28)
[2020-03-11 09:00:05][vHmqrBYeLtK3Lbiq5TsTZxBo2igaCZHC] Processed:  Closure (DispatcherFactory.php:28)
[2020-03-11 09:00:08][LXdzLvilh5qhew7akNDnibCjaXksG81X] Processing: Closure (DispatcherFactory.php:28)
[2020-03-11 09:00:08][LXdzLvilh5qhew7akNDnibCjaXksG81X] Processed:  Closure (DispatcherFactory.php:28)
[2020-03-11 09:00:11][MnPIqk5fCwXjiVzuwPjkkOdPPBn0xR4d] Processing: Closure (DispatcherFactory.php:28)
[2020-03-11 09:00:11][MnPIqk5fCwXjiVzuwPjkkOdPPBn0xR4d] Processed:  Closure (DispatcherFactory.php:28)
[2020-03-11 09:00:11][I2hvBoCB71qZQeD4umn5dd90zJUCAlJ5] Processing: App\Jobs\MyJob
Hello!
[2020-03-11 09:00:11][I2hvBoCB71qZQeD4umn5dd90zJUCAlJ5] Processed:  App\Jobs\MyJob

For more details and source code, you can visit its complete documentation on Github.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Automatically Detect & Set App Locale with Laravel Localizer

 Programing Coderfunda     November 29, 2022     Laravel, laravel-packages, php     No comments   

 Laravel Localizer is an awesome package that allows you to automatically detect and set an app locale that matches your visitor's preference.

  • Define your supported locales and match your visitor's preference
  • Uses the most common locale detectors by default
  • Uses the most common locale stores by default
  • Easily create and add your own detectors and stores

Requirements

  • PHP >= 7.1
  • Laravel >= 5.6

Installation

You can install this package via composer by running this command.

composer require codezero/laravel-localizer

Laravel will automatically register the ServiceProvider.

Add Middleware

Add the middleware to the web middleware group in app/Http/Kernel.php, after StartSession and before SubstituteBindings:

protected $middlewareGroups = [
    'web' => [
        \Illuminate\Session\Middleware\StartSession::class, // <= after this
        //...
        \CodeZero\Localizer\Middleware\SetLocale::class,
        //...
        \Illuminate\Routing\Middleware\SubstituteBindings::class, // <= before this
    ],
];

In Laravel 6.x you also need to add the middleware to the $middlewarePriority array in app/Http/Kernel.php to trigger it in the correct order:

protected $middlewarePriority = [
    \Illuminate\Session\Middleware\StartSession::class, // <= after this
    //...
    \CodeZero\Localizer\Middleware\SetLocale::class,
    //...
    \Illuminate\Routing\Middleware\SubstituteBindings::class, // <= before this
];

Publish Configuration File

php artisan vendor:publish --provider="CodeZero\Localizer\LocalizerServiceProvider" --tag="config"

You will now find a localizer.php file in the config folder.

Configure Supported Locales

Add any locales you wish to support to your published config/localizer.php file:

'supported-locales' => ['en', 'nl', 'fr'];

Drivers

Detectors

By default, the middleware will use the following detectors to check for a supported locale:

  1. The URL slug
  2. The session
  3. A cookie
  4. The browser
  5. The app's default locale

If you publish the configuration file, you can choose which detectors to run and in what order.

You can also create your own detector by implementing the \CodeZero\Localizer\Detectors\Detector interface and add a reference to it in the config file. The detectors are resolved from Laravel's IOC container so that you can add any dependencies to your constructor.

Stores

The first supported locale that is returned by a detector will then be stored in:

  1. The session
  2. A cookie
  3. The app locale

If you publish the configuration file, you can choose which stores to use.

You can also create your own store by implementing the \CodeZero\Localizer\Stores\Store interface and add a reference to it in the config file. The stores are resolved from Laravel's IOC container, so you can add any dependencies to your constructor.

For more details, please visit Github.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Create Collection of dates & times with Laravel Hours Helper

 Programing Coderfunda     November 29, 2022     Laravel, laravel-packages, php     No comments   

 Laravel Hours Helper is an amazing package that helps you to create an Illuminate\Support\Collection of dates and times with a specific interval for a specific period. This helper could be useful in generating dropdown selections for a calendar meeting invite or scheduling the duration of an event. This helper also allows you to define the date formatting for each interval and to exclude intervals within the specific period.

Requirements

Laravel 8.x or 9.x

Installation

Install the package via composer:

composer require label84/laravel-hours-helper

Usage

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('08:00', '09:30', 30);

// Illuminate\Support\Collection
0 => '08:00',
1 => '08:30',
2 => '09:00',
3 => '09:30',

Example 1: time format

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('11:00', '13:00', 60, 'g:i A');

// Illuminate\Support\Collection
0 => '11:00 AM',
1 => '12:00 PM',
2 => '1:00 PM',

Example 2: exclude times

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('08:00', '11:00', 60, 'H:i', [
    ['09:00', '09:59'],
    // more..
]);

// Illuminate\Support\Collection
0 => '08:00',
1 => '10:00',
2 => '11:00',

Example 3: past midnight

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('23:00', '01:00', 60);

// Illuminate\Support\Collection
0 => '23:00',
1 => '00:00',
2 => '01:00',

Example 4: multiple days

use Label84\HoursHelper\Facades\HoursHelper;

$hours = HoursHelper::create('2022-01-01 08:00', '2022-01-01 08:30', 15, 'Y-m-d H:i');

// Illuminate\Support\Collection
0 => '2022-01-01 08:00',
1 => '2022-01-01 08:15',
2 => '2022-01-01 08:30',

For more details and source code, please visit Github.

Note

If you are an enterprise and want to use develop a CRM, e-commerce, or SAAS web application in Laravel, you must discover an impeccable team with proficiency in the Laravel framework. So Codebrisk is here to help you with your tailored requirements regarding Laravel Development. Our CRM development with Laravel holds a wide range of features for entities to manage their interactions with customers.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Laravel Package to Help with Loading Files into MySQL Tables

 Programing Coderfunda     November 29, 2022     Laravel, laravel-packages, php     No comments   

 Laravel Load File is a package to help with loading files into MySQL tables. This uses MySQL's LOAD DATA statement to load text files quickly into your database. This is usually 20 times faster than using INSERT statements according to: https://dev.mysql.com/doc/refman/8.0/en/insert-optimization.html

Options

This library currently can handle any of the options in a normal LOAD DATA statement except for the partitioned table support. This will be included in a future release of the laravel-loadfile.

Installation

Requires > PHP 8.0 and > Laravel 8

composer require ellgreen/laravel-loadfile

Loading files

To use local files you will need to have local_infile enabled for the client and server. To do this on the Laravel side you will need to add the following to the options part of your database config:

'config' => [
    PDO::MYSQL_ATTR_LOCAL_INFILE => true,
],

Simple file import

use EllGreen\LaravelLoadFile\Laravel\Facades\LoadFile;

LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    ->load();

Ignoring header row

LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    ->ignoreLines(1)
    ->load();

Specifying field options

LoadFile::file('/path/to/employees.csv', $local = true)
    ->into('employees')
    ->columns(['forename', 'surname', 'employee_id'])
    // like this
    ->fieldsTerminatedBy(',')
    ->fieldsEscapedBy('\\\\')
    ->fieldsEnclosedBy('"')
    // or
    ->fields(',', '\\\\', '"')
    ->load();

Loading data into Eloquent Models

Simply add the LoadsFiles trait to your model like so:

use EllGreen\LaravelLoadFile\Laravel\Traits\LoadsFiles;

class User extends Model
{
    use LoadsFiles;
}

Then you can use the following method to load a file into that table:

User::loadFile('/path/to/users.csv', $local = true);

Need to specify options to load the file with?

Add the following method to your Model

class User extends Model
{
    use LoadsFiles;

    public function loadFileOptions(Builder $builder): void
    {
        $builder
            ->fieldsTerminatedBy(',')
            ->ignoreLines(1);
    }
}

Or you can get an instance of the query builder on the fly

User::loadFileBuilder($file, $local)
    ->replace()
    ->ignoreLines(1)
    ->load();

For more details, visit Github.

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Use Flags For Countries & Languages in Laravel Blade Views

 Programing Coderfunda     November 29, 2022     Laravel, laravel-packages, php     No comments   

 Blade Flags is a package to efficiently use TwEmoji Countries & Languages Flags in your Laravel Blade views. You can use it easily to display countries & languages flags in your Laravel Blade views. For a complete list of available icons see the SVG directory or preview all the available flags, check the gallery.

Requirements

  • PHP 8.0 or higher
  • Laravel 9.0 or higher

Installation

You can install this package via composer by running this command in your terminal:

composer require outhebox/blade-flags

Blade Icons

Blade Flags uses Blade Icons under the hood. Please refer to the Blade Icons readme for additional functionality. We also recommend enabling icon caching with this library.

Configuration

Blade Flags also offers the ability to use features from Blade Icons like default classes, default attributes, etc. If you'd like to configure these, publish the blade-flags.php config file:

php artisan vendor:publish --tag=blade-flags-config

Usage

Icons can be used as self-closing Blade components which will be compiled into SVG icons:

<x-flag-country-br />
<x-flag-country-cn />
<x-flag-country-gb />
<x-flag-country-ru />
<x-flag-country-us />
<x-flag-language-en />
<x-flag-language-ar />
<x-flag-language-es />

You can also pass classes to your icon components:

<x-flag-country-us class="w-6 h-6"/>

Raw SVG Icons

If you want to use the raw SVG icons as assets, you can publish them using:

php artisan vendor:publish --tag=blade-flags --force

Then use them in your views like:

<img src="{{ asset('vendor/blade-flags/country-us.svg') }}" width="32" height="32"/>
<img src="{{ asset('vendor/blade-flags/language-en.svg') }}" width="32" height="32"/>

For more details about this package, You can visit Github.


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Optimize & store images in multiple sizes easily in Laravel

 Programing Coderfunda     November 29, 2022     Laravel, laravel-packages, php     No comments   

 Laravel Image Handler is an awesome package that can be used to optimize and store images in multiple sizes easily.
Installationcomposer require codepane/laravel-image-handlerphp artisan vendor:publish --provider="codepane\LaravelImageHandler\ImageHandlerServiceProvider"UsageStore Imageuse ImageHandler;public function store() {// its takes the default file name as it is ImageHandler::store($request->file);// in 2nd argument you can pass your custom file name with or without the path ImageHandler::store($request->file, 'file_name_with_or_without_path');}use ImageHandler;public function get() {// this will return the original image ImageHandler::get('original_file_name');// pass dimension as the second argument to get a specific dimension of the file ImageHandler::get('original_file_name', 'sm');}use ImageHandler;public function delete() { ImageHandler::delete('original_file_name');}x
You can install this package via composer by running this command in terminal
Run this command too publish:
Configuration
After installation is done once you can see imagehandler.php under the config directory. You can update dimensions, format, and quality as per your need from a configuration file. You can also add a new dimension.
Let's deep dive into this package for how to use it
Get Image
Delete Image
For more details, please visit Github.
Closing Note
The team of Codebrisk Laravel developers is always ready to execute even your boldest ideas. Our expert team can design and develop any type of custom CRM solution, SAAS app, or e-commerce app to meet our customer's needs and transform our customer's experiences. Get in touch with our team to discuss your bespoke ideas and learn more about the next steps to launching cooperation.
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Meta

Popular Posts

  • Credit card validation in laravel
      Validation rules for credit card using laravel-validation-rules/credit-card package in laravel Install package laravel-validation-rules/cr...
  • Write API Integrations in Laravel and PHP Projects with Saloon
    Write API Integrations in Laravel and PHP Projects with Saloon Saloon  is a Laravel/PHP package that allows you to write your API integratio...
  • iOS 17 Force Screen Rotation not working on iPAD only
    I have followed all the links on Google and StackOverFlow, unfortunately, I could not find any reliable solution Specifically for iPad devic...
  • C++ in Hindi Introduction
    C ++ का परिचय C ++ एक ऑब्जेक्ट ओरिएंटेड प्रोग्रामिंग लैंग्वेज है। C ++ को Bjarne Stroustrup द्वारा विकसित किया गया था। C ++ में आने से पह...
  • Python AttributeError: 'str' has no attribute glob
    I am trying to look for a folder in a directory but I am getting the error.AttributeError: 'str' has no attribute glob Here's ...

Categories

  • Ajax (26)
  • Bootstrap (30)
  • DBMS (42)
  • HTML (12)
  • HTML5 (45)
  • JavaScript (10)
  • Jquery (34)
  • Jquery UI (2)
  • JqueryUI (32)
  • Laravel (1017)
  • Laravel Tutorials (23)
  • Laravel-Question (6)
  • Magento (9)
  • Magento 2 (95)
  • MariaDB (1)
  • MySql Tutorial (2)
  • PHP-Interview-Questions (3)
  • Php Question (13)
  • Python (36)
  • RDBMS (13)
  • SQL Tutorial (79)
  • Vue.js Tutorial (68)
  • Wordpress (150)
  • Wordpress Theme (3)
  • codeigniter (108)
  • oops (4)
  • php (853)

Social Media Links

  • Follow on Twitter
  • Like on Facebook
  • Subscribe on Youtube
  • Follow on Instagram

Pages

  • Home
  • Contact Us
  • Privacy Policy
  • About us

Blog Archive

  • July (2)
  • September (100)
  • August (50)
  • July (56)
  • June (46)
  • May (59)
  • April (50)
  • March (60)
  • February (42)
  • January (53)
  • December (58)
  • November (61)
  • October (39)
  • September (36)
  • August (36)
  • July (34)
  • June (34)
  • May (36)
  • April (29)
  • March (82)
  • February (1)
  • January (8)
  • December (14)
  • November (41)
  • October (13)
  • September (5)
  • August (48)
  • July (9)
  • June (6)
  • May (119)
  • April (259)
  • March (122)
  • February (368)
  • January (33)
  • October (2)
  • July (11)
  • June (29)
  • May (25)
  • April (168)
  • March (93)
  • February (60)
  • January (28)
  • December (195)
  • November (24)
  • October (40)
  • September (55)
  • August (6)
  • July (48)
  • May (2)
  • January (2)
  • July (6)
  • June (6)
  • February (17)
  • January (69)
  • December (122)
  • November (56)
  • October (92)
  • September (76)
  • August (6)

Loading...

Laravel News

Loading...

Copyright © CoderFunda | Powered by Blogger
Design by Coderfunda | Blogger Theme by Coderfunda | Distributed By Coderfunda