megacolorboy

Abdush Shakoor's Weblog

Writings, experiments & ideas.

Integrate Excel into your Laravel project

Before you integrate Excel into your application, make sure your project meets the following requirements:

  • PHP v7.0 or greater
  • Laravel v5.5 or greater
  • PhpSpreadsheet v1.6 or greater

Download the package

Download the maatwebsite/excel package using Composer:

composer require maatwebsite/excel

Add it to service provider

By default, this will be done automatically when you're installing the package but if you want to do it yourself, add this in your config/app.php file:

<?php
// ...
'providers' => [
    // ...
    Maatwebsite\Excel\ExcelServiceProvider::class,
],

// ...
'aliases' => [
    // ...
    'Excel' => 'Maatwebsite\Excel\Facades\Excel::class',
],
?>;

Publish your configuration

Last but not the least, run the vendor:publish command using artisan to publish your configuration:

php artisan vendor:publish -provider="Maatwebsite\Excel\ExcelServiceProvider"

Upon publishing, the config/excel.php configuration file will be created where you can make your changes.

Hope this helps you out!

Find files containing specific text

This helped me a lot whenever I'm in a remote server trying to find a keyword or specific text amongst a bunch of files.

This command will save you a lot of time:

grep -rwn [path] -e 'pattern'
  • r stands for recursion
  • n displays the line number
  • w matches the whole word

Refer to man find pages for more info.

Find a file by extension

This comes in handy whenever I want to look for files that exists with a specific extension in a computer or server:

find . -name "*.ext"

In addition, sometimes, you might want to look for a bunch of files with a specific extension but with matching keywords:

find .name "*.ext" | grep "keyword"

Hope you found this helpful!

Including and excluding files in zip

When zipping a directory or a bunch of files, there'll be a lot of stuff that you want to include and exclude.

To exclude a file:

zip -r files.zip . -x file_1 file_2

Alternatively, you can choose to include files:

zip -r files.zip . -i file_1 file_2

Insert mode

I get it, a lot of people are confused on how to start typing on VIM. All you have to do is press the A key, the editor will be switched to insert mode.

Press ESC key to switch back to normal mode.

Quit VIM

One of the most infamous issues that new users of VIM faces when using it for the first time. Press :q to quit VIM

If you've worked on a file and want to save and quit? Just type :wq!.

I hope that solved your quitting issue with VIM.

Save a file

Want to save your work? Type :w

Type :wq! to save your file and quit VIM at the same time.

Set up reCaptcha in Laravel

I mean, come on, you need to have a reCaptcha in your forms, no matter what.

Here are the steps:

1. Install using Composer

composer require anhskohbo/no-captcha

2. Add provider and alias to configuration

Open your config/app.php file and add this to your providers array:

<?php
Anhskohbo\NoCaptcha\NoCaptchaServiceProvider::class,
?>

And this to your aliases array:

<?php
'NoCaptcha' => Anhskohbo\NoCaptcha\Facades\NoCaptcha::class,
?>

3. Publish configuration

php artisan vendor:publish --provider="Anhskohbo\NoCaptcha\NoCaptchaServiceProvider"

4. Add sitekey and secret key to .env file

Open your .env file and add this:

NOCAPTCHA_SITEKEY=yoursitekey
NOCAPTCHA_SECRET=yoursecret

How to use it?

Now, you can use it in your validator using like this:

<?php
$validate = Validator::make(Input::all(),[
    'g-recaptcha-response' => 'required|captcha'
]);
?>