<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nkwaten</title>
    <description>The latest articles on Forem by Nkwaten (@nkwaten).</description>
    <link>https://forem.com/nkwaten</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F884773%2F70fc6b5b-8e35-4bdf-b7a3-d3e051ca4b81.jpg</url>
      <title>Forem: Nkwaten</title>
      <link>https://forem.com/nkwaten</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/nkwaten"/>
    <language>en</language>
    <item>
      <title>Encrypting Sensitive Information using Laravel Database Encryption Package</title>
      <dc:creator>Nkwaten</dc:creator>
      <pubDate>Tue, 31 Oct 2023 16:15:42 +0000</pubDate>
      <link>https://forem.com/nkwaten/encrypting-sensitive-information-using-laravel-database-encryption-package-5fj6</link>
      <guid>https://forem.com/nkwaten/encrypting-sensitive-information-using-laravel-database-encryption-package-5fj6</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In this guide, we are going to learn how to encrypt our databases in our Laravel application to protect data. Developers sometimes consider encryption an afterthought but it is essential that encryption techniques are considered in the early stage of development especially when dealing with sensitive user data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Laravel: Laravel is a web application framework with expressive, elegant syntax. Supported versions &amp;gt; 5.x.x. The version used in this guide is Laravel 8.&lt;/p&gt;

&lt;p&gt;Laravel Database Encryption Package: This is a package from Elgiborsolution for encrypting and decrypting model attributes for Laravel using OpenSSL. The package is simple and easy to use. All you need to to specify the fields/attributes you want to encrypt and "voila" the work is done.  The package uses the encryption key in your .env.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tutorial&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
Install the package via composer using the command line&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;$ composer require elgibor-solution/laravel-database-encryption&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
To encrypt a field of data use the EncryptedAttribute trait in the model where you want to apply the encryption. For example, if you want to encrypt the name_of_spouse, address_of_spouse and occupation_of_spouse attributes  in the Family model, you do the following:
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use ESolution\DBEncryption\Traits\EncryptedAttribute;

class Family extends Model
{

    use EncryptedAttribute;

    protected $encryptable = [
        'name_of_spouse','maiden_name_of_spouse','address_of_spouse'
    ];

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This tells the package which properties are to be encrypted.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;If you have an empty database and have not run migrations, you can run your database migrations and the columns are automatically encrypted.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If you already have data in your database you can encrypt it with the following artisan command. &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;php artisan encryptable:encryptModel 'App\Models\Family'&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
And that's how you protect user data by working with Laravel database encryption. &lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Other features *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;To decrypt your database you use the following artisan command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;php artisan encryptable:decryptModel 'App\Models\Family'&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
To decrypt a record in your controller you can use Encrypter method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use ESolution\DBEncryption\Encrypter;

class RecordsController extends Controller{

 public function index(){

            'name_of_spouse'=&amp;gt;Encrypter::decrypt($family-&amp;gt;name_of_spouse),

}

}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To learn more about the package read the documentation and give them a star on GitHub&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/elgiborsolution/laravel-database-encryption#laravel-database-encryption-package"&gt;https://github.com/elgiborsolution/laravel-database-encryption#laravel-database-encryption-package&lt;/a&gt;&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>database</category>
      <category>encryption</category>
    </item>
    <item>
      <title>IMPLEMENTING RESUMABLE FILE UPLOADS IN PHP WITH LARAVEL 8, UPPY AND TUS</title>
      <dc:creator>Nkwaten</dc:creator>
      <pubDate>Thu, 30 Jun 2022 20:04:29 +0000</pubDate>
      <link>https://forem.com/nkwaten/implementing-resumable-file-uploads-in-php-with-laravel-8-uppy-and-tus-4h8</link>
      <guid>https://forem.com/nkwaten/implementing-resumable-file-uploads-in-php-with-laravel-8-uppy-and-tus-4h8</guid>
      <description>&lt;p&gt;The following guide helps you to implement a little fancier file uploads for your web apps&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://laravel.com/"&gt;Laravel&lt;/a&gt;: Laravel is a web application framework with expressive, elegant syntax. Supported versions &amp;gt; 5.x.x . The version used in this guide is Laravel 8.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://uppy.io/"&gt;Uppy&lt;/a&gt;: Sleek, modular open source JavaScript file uploader.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mIS013l9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/poa12re28u3rxllnj83b.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mIS013l9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/poa12re28u3rxllnj83b.JPG" alt="Image description" width="623" height="502"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://tus.io/"&gt;Tus&lt;/a&gt;: Open Protocol for Resumable File Uploads.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ankitpokhrel/tus-php"&gt;Tus-PHP&lt;/a&gt;:  A pure PHP server and client for the tus resumable upload protocol v1.0.0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://redis.io/"&gt;Redis&lt;/a&gt;: An open source (BSD licensed), in-memory data structure store, used as a database, cache, and message broker.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tutorial&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;1.Install Uppy and its supported plugins (Dashboard, Tus) with NPM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install uppy

npm install @uppy/dashboard

npm install @uppy/tus

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create your file upload element in your blade file. In this example, we are using a button.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;button  type='button' class='btn btn-success btn-sm' id='file_upload' name='file_upload'&amp;gt;Upload File&amp;lt;/button&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.In order to post your file to your /tus endpoint, you need to add CSRF-TOKEN. Create a meta tag to hold your token in the blade.php which you will pass to your Uppy.js.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;meta name="csrf-token" content={"{ csrf_token() }}"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.Create your Uppy configuration in your JavaScript file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import Uppy from '@uppy/core';
import Tus from '@uppy/tus'
import Dashboard from '@uppy/dashboard';


const uppy = new Uppy({
    debug: false,
    autoProceed: false,
    restrictions: {
      maxFileSize: 1000000,
      maxNumberOfFiles: 1,
      allowedFileTypes: ['image/*'],
    }
})
.use(Dashboard, {
target: 'body',
  trigger: '#file_upload',
  closeAfterFinish: true,
  browserBackButtonClose: false,
  showProgressDetails: true,
})
.use(Tus, {
    endpoint: '/tus', // use your tus endpoint here
    retryDelays: [0, 1000, 3000, 5000],
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
})
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We need Redis for cache management. Go ahead and follow the &lt;a href="https://redis.io/docs/getting-started/installation/"&gt;guide&lt;/a&gt; for installing Redis on your system. If you’re running a Windows system you need to install Windows Subsystem for Linux before you begin. I will recommend the Ubuntu distro.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

sudo apt-get update
sudo apt-get install redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Start the Redis server
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;redis-server

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Confirm that your redis server is running smoothly and can connect to it
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;redis-cli ping

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;We will now tie everything together with the Tus-PHP from Ankit Pokhrel. Add Tus-PHP with Composer
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require ankitpokhrel/tus-php

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Create a service provider (eg. TusServiceProvider) and add it to your config config/app.php.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan make:provider TusServiceProvider

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Update the provider with the sample code from the Laravel integration guide. You do not have to exclude the server endpoint from Laravel’s CSRF validation. That’s a security risk and has been taken care of by passing it in the headers. Also, remember to create your upload folder in the storage
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use TusPhp\Tus\Server as TusServer;


class TusServiceProvider extends ServiceProvider
{
    /**
     * Register services.
     *
     * @return void
     */
    public function register()
    {
        //
        $this-&amp;gt;app-&amp;gt;singleton('tus-server', function ($app) {
            $server = new TusServer('redis');

            $server-&amp;gt;setApiPath('/tus');
            $server-&amp;gt;setUploadDir(storage_path('app/public/uploads'));

            return $server;
        });

    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Add the /tus endpoint to your route to serve requests.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::any('/tus/{any?}', function () {
    return app('tus-server')-&amp;gt;serve();
})-&amp;gt;where('any', '.*');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WhkvGAcc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1a2mlbnx6y4rgnmsxso2.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WhkvGAcc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1a2mlbnx6y4rgnmsxso2.jpg" alt="Image description" width="694" height="562"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s all folks. Users will be able to resume the upload of files after an network error or closing the browser. Hit the &lt;a href="https://nkwaten.wordpress.com/2022/06/25/implementing-resumable-file-uploads-in-php-with-laravel-8-uppy-and-tus/"&gt;comments&lt;/a&gt; if you need any help.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>tus</category>
      <category>uppy</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
