<?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: Erland Muchasaj</title>
    <description>The latest articles on Forem by Erland Muchasaj (@erlandmuchasaj).</description>
    <link>https://forem.com/erlandmuchasaj</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%2F1040225%2Fcf0ea56f-7c7a-4a21-8d89-60068d8c72c8.png</url>
      <title>Forem: Erland Muchasaj</title>
      <link>https://forem.com/erlandmuchasaj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/erlandmuchasaj"/>
    <language>en</language>
    <item>
      <title>Final and Readonly Classes in PHP</title>
      <dc:creator>Erland Muchasaj</dc:creator>
      <pubDate>Tue, 21 Mar 2023 17:47:55 +0000</pubDate>
      <link>https://forem.com/erlandmuchasaj/final-and-readonly-classes-in-php-38fi</link>
      <guid>https://forem.com/erlandmuchasaj/final-and-readonly-classes-in-php-38fi</guid>
      <description>&lt;h2&gt;
  
  
  final classes
&lt;/h2&gt;

&lt;p&gt;In the past, when you didn't want other classes to extend a certain class, you could mark it as &lt;code&gt;final&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Consider the code below :&lt;/p&gt;

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

&amp;lt;?php

namespace App\Utils;

class ParentClass
{
    public function __construct(protected string $name) {
    }
}



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

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

&amp;lt;?php

namespace App\Utils;

class ChildClass extends ParentClass
{

}



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

&lt;/div&gt;

&lt;p&gt;So we have a &lt;code&gt;ParentClass&lt;/code&gt; and a &lt;code&gt;ChildClass&lt;/code&gt; that extends the parent.&lt;/p&gt;

&lt;p&gt;we could use the &lt;code&gt;ChildClass&lt;/code&gt; as following:&lt;/p&gt;

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

&amp;lt;?php

use App\Utils\ChildClass;

$obj = new ChildClass('Antonio');

var_dump($obj);



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

&lt;/div&gt;

&lt;p&gt;And this would output &lt;code&gt;ChildClass&lt;/code&gt; public properties and also inherited properties from &lt;code&gt;ParentClass&lt;/code&gt; as follows:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0pehhstxybr4t03rfu94.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F0pehhstxybr4t03rfu94.png" alt="result of Dump and Die"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now if we do not want our class to be extended we just put the word &lt;code&gt;final&lt;/code&gt; at the beginning of the class as follows: &lt;/p&gt;

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

&amp;lt;?php

namespace App\Utils;

final class ParentClass
{
    public function __construct(
        protected string $name,
    ) {
    }
}



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

&lt;/div&gt;

&lt;p&gt;and calling the &lt;code&gt;$obj = new ChildClass('Antonio');&lt;/code&gt; again would result in: &lt;code&gt;Class App\Utils\ChildClass cannot extend final class App\Utils\ParentClass&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So the definition of &lt;code&gt;final&lt;/code&gt; in php is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The final keyword is used to prevent a class from being inherited and to prevent inherited method from being overridden.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;So if we declare class method as a &lt;code&gt;final&lt;/code&gt; then that method cannot be override by the child class.&lt;/li&gt;
&lt;li&gt;Same as method if we declare class as a &lt;code&gt;final&lt;/code&gt; then that class cannot be extended any more.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  readonly class
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;readonly&lt;/code&gt; classes are added on &lt;a href="https://www.php.net/releases/8.2/en.php#readonly_classes" rel="noopener noreferrer"&gt;&lt;code&gt;PHP 8.2&lt;/code&gt;&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;final&lt;/code&gt;and &lt;code&gt;readonly&lt;/code&gt;are two completely different concepts in PHP and have different implications when applied to a class.&lt;/p&gt;

&lt;p&gt;As we saw earlier, making a class &lt;code&gt;final&lt;/code&gt; means that it cannot be extended.&lt;/p&gt;

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

final class ParentClass{}

// Fatal error: Class ChildClass cannot extend final class ParentClass
class ChildClass extends ParentClass{}


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

&lt;/div&gt;

&lt;p&gt;In the other hand, making a class &lt;code&gt;readonly&lt;/code&gt; means several things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;All instance properties of a class are implicitly marked as readonly, and cannot be reassigned.&lt;/li&gt;
&lt;li&gt;Creation of dynamic properties is not allowed.&lt;/li&gt;
&lt;li&gt;Only a readonly class can extend another readonly class.&lt;/li&gt;
&lt;li&gt;readonly properties can be overridden&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For example: &lt;/p&gt;

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

// PHP 8.2+
readonly class ParentClass
{
    public function __construct(
        public string $name
    ) {}
}

$obj = new ParentClass('Antonio');
echo 'Hello, My name is ' . $obj -&amp;gt;name; // "Hello, My name is Antonio"


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

&lt;/div&gt;

&lt;p&gt;If you try to re-assign a value to any object property after instantiation, it would throw the following error:&lt;/p&gt;

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

// PHP 8.2+
// Fatal error: Uncaught Error: Cannot modify readonly property ParentClass::$name
$obj -&amp;gt;name = 'Ndershkuesi';


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

&lt;/div&gt;

&lt;p&gt;This happens because all properties are implicitly readonly when you mark the class as readonly.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: &lt;code&gt;readonly&lt;/code&gt; property cannot have default value.&lt;/p&gt;

&lt;h2&gt;
  
  
  final and readonly
&lt;/h2&gt;

&lt;p&gt;You can also mark a class as both &lt;code&gt;readonly&lt;/code&gt; and &lt;code&gt;final&lt;/code&gt; as well, this means:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;All class properties are implicitly &lt;code&gt;readonly&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The class cannot be extended.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example:&lt;/p&gt;

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

// PHP 8.2+
final readonly class ParentClass {
    public function __construct(
        public string $name
    ) {}
}


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

&lt;/div&gt;

&lt;p&gt;Usage:&lt;/p&gt;

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

$obj = new ParentClass('Antonio');
echo 'My name is ' . $obj-&amp;gt;name; // "My name is Antonio"


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

&lt;/div&gt;

&lt;p&gt;And if you try to assign a value to any object property or if you try to extend the class then it would throw an error as follows:&lt;/p&gt;

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

// PHP 8.2+

// Fatal error: Uncaught Error: Cannot modify readonly property ParentClass::$name
$obj-&amp;gt;name = 'Ndershkuesi';

// Fatal error: Class ChildClass cannot extend final class Shape
readonly class ChildClass extends ParentClass {}


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

&lt;/div&gt;




&lt;h2&gt;
  
  
  Was it helpful?
&lt;/h2&gt;

&lt;p&gt;Let me know in the comment section below if you ever use this package in any of your projects.&lt;/p&gt;

&lt;p&gt;Don’t forget to &lt;em&gt;like&lt;/em&gt; and &lt;em&gt;comment&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/muchasaj" rel="noopener noreferrer"&gt;me&lt;/a&gt; for more web development tips, new packages and more.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>webdev</category>
      <category>laravel</category>
    </item>
    <item>
      <title>Upload files on Laravel 10</title>
      <dc:creator>Erland Muchasaj</dc:creator>
      <pubDate>Tue, 07 Mar 2023 17:20:00 +0000</pubDate>
      <link>https://forem.com/erlandmuchasaj/upload-files-on-laravel-10-po8</link>
      <guid>https://forem.com/erlandmuchasaj/upload-files-on-laravel-10-po8</guid>
      <description>&lt;p&gt;Uploading files is one common feature that most of the applications use, and yet is one of the things that I see many people struggling with.&lt;/p&gt;

&lt;p&gt;Laravel offers a simple API to work with local filesystem as simple as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Storage::putFileAs('images', $request-&amp;gt;file('file'));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Often user needs to handle file validation, &lt;em&gt;file size&lt;/em&gt;, &lt;em&gt;dimensions&lt;/em&gt;, &lt;em&gt;name&lt;/em&gt;, &lt;em&gt;visibility&lt;/em&gt;, &lt;em&gt;path&lt;/em&gt;, &lt;em&gt;disk&lt;/em&gt; etc.&lt;/p&gt;

&lt;p&gt;We will want to create a form that allows us to upload a file and submit it - and a route will accept this form, validate the input and handle the upload.&lt;/p&gt;

&lt;p&gt;With this article, I will do a step-by-step file upload tutorial on Laravel 10 using &lt;a href="https://github.com/erlandmuchasaj/laravel-file-uploader"&gt;erlandmuchasaj/laravel-file-uploader&lt;/a&gt; package. &lt;br&gt;
In this Tutorial we will generate 2 routes.&lt;br&gt;
One for creating a form where user will upload the file and another route for the file to be uploaded using the package.&lt;br&gt;
We will create a simple form using &lt;a href="https://getbootstrap.com/docs/5.2/forms/overview/"&gt;Bootstrap Form UI components&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First things first, lets setup a brand new Laravel project.&lt;br&gt;
Open the command-line tool and execute the following command to create a Laravel project from scratch.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer create-project laravel/laravel --prefer-dist laravel-file-uploader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then we go into the freshly created project directory:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd laravel-file-uploader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Then we install the &lt;a href="https://github.com/erlandmuchasaj/laravel-file-uploader"&gt;laravel-file-uploader&lt;/a&gt; package.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require erlandmuchasaj/laravel-file-uploader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;After that we create a symbolic link to access the files that are going to be publicly accessible.&lt;br&gt;
By default, the &lt;code&gt;public&lt;/code&gt; disk uses the &lt;code&gt;local&lt;/code&gt; driver and stores its files in &lt;code&gt;storage/app/public&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To make these files accessible from the web, you should create a symbolic link from &lt;code&gt;public/storage&lt;/code&gt; to &lt;code&gt;storage/app/public&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To create the symbolic link, you may use the storage:link Artisan command:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;php artisan storage:link
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Create routes.
&lt;/h2&gt;

&lt;p&gt;Go to &lt;code&gt;route/web.php&lt;/code&gt; and create 2 additional routes. The first handles the form visualization and the other handles the form POST request.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;use ErlandMuchasaj\LaravelFileUploader\FileUploader; // &amp;lt;= import the package
use Illuminate\Support\Facades\Route;
use Illuminate\Http\Request;


// visualize the form
Route::get('/files', function (Request $request) {
    return view('files');
})-&amp;gt;name('files');

// handle the post request
Route::post('/files', function (Request $request) {

    $max_size = (int) ini_get('upload_max_filesize') * 1000;

    $extensions = implode(',', FileUploader::images());

    $request-&amp;gt;validate([
        'file' =&amp;gt; [
            'required',
            'file',
            'image',
            'mimes:' . $extensions,
            'max:'.$max_size,
        ]
    ]);

    $file = $request-&amp;gt;file('file');

    $response = FileUploader::store($file);

    return redirect()
            -&amp;gt;back()
            -&amp;gt;with('success','File has been uploaded.')
            -&amp;gt;with('file', $response);
})-&amp;gt;name('files.store');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Creating the blade files in Laravel.
&lt;/h2&gt;

&lt;p&gt;In this step we create the view where the file uploader form will be placed.&lt;br&gt;
Create a new file in &lt;code&gt;resources/views/files.blade.php&lt;/code&gt; and place the following content:&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;!DOCTYPE html&amp;gt;
&amp;lt;html lang="{{ str_replace('_', '-', app()-&amp;gt;getLocale()) }}"&amp;gt;
    &amp;lt;head&amp;gt;
        &amp;lt;meta charset="utf-8"&amp;gt;
        &amp;lt;meta name="viewport" content="width=device-width, initial-scale=1"&amp;gt;
        &amp;lt;title&amp;gt;File uploader&amp;lt;/title&amp;gt;
        &amp;lt;link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"&amp;gt;
    &amp;lt;/head&amp;gt;
    &amp;lt;body class="antialiased"&amp;gt;
        &amp;lt;div class="container"&amp;gt;
            &amp;lt;div class="row"&amp;gt;
                &amp;lt;div class="col-12"&amp;gt;
                    @if ($message = Session::get('success'))
                        &amp;lt;div class="alert alert-success alert-dismissible fade show" role="alert"&amp;gt;
                            &amp;lt;button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"&amp;gt;&amp;lt;/button&amp;gt;
                            &amp;lt;strong&amp;gt;{{ $message }}&amp;lt;/strong&amp;gt;
                        &amp;lt;/div&amp;gt;
                    @endif
                    @if (count($errors) &amp;gt; 0)
                        &amp;lt;div class="alert alert-danger alert-dismissible fade show" role="alert"&amp;gt;
                            &amp;lt;button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"&amp;gt;&amp;lt;/button&amp;gt;
                            &amp;lt;ul class="mb-0 p-0"&amp;gt;
                                @foreach ($errors-&amp;gt;all() as $error)
                                    &amp;lt;li&amp;gt;{{ $error }}&amp;lt;/li&amp;gt;
                                @endforeach
                            &amp;lt;/ul&amp;gt;
                        &amp;lt;/div&amp;gt;
                    @endif
                &amp;lt;/div&amp;gt;
                &amp;lt;div class="col-12 py-5"&amp;gt;
                    &amp;lt;div class="card my-5"&amp;gt;
                        &amp;lt;div class="card-header"&amp;gt;
                           &amp;lt;h3&amp;gt;Laravel File Uploader&amp;lt;/h3&amp;gt;
                        &amp;lt;/div&amp;gt;
                        &amp;lt;div class="card-body"&amp;gt;
                            &amp;lt;form method="POST" action="{{ route('files.store')  }}" enctype="multipart/form-data"&amp;gt;
                                @method('POST')
                                @csrf
                                &amp;lt;div class="mb-3"&amp;gt;
                                    &amp;lt;label for="formFileLg" class="form-label"&amp;gt;File input example&amp;lt;/label&amp;gt;
                                    &amp;lt;input name="file" class="form-control form-control-lg" id="formFileLg"
                                           type="file"&amp;gt;
                                &amp;lt;/div&amp;gt;
                                &amp;lt;div class="mb-3"&amp;gt;
                                    &amp;lt;button type="submit" value="submit" class="btn btn-primary"&amp;gt;Upload&amp;lt;/button&amp;gt;
                                &amp;lt;/div&amp;gt;
                            &amp;lt;/form&amp;gt;
                        &amp;lt;/div&amp;gt;
                    &amp;lt;/div&amp;gt;
                &amp;lt;/div&amp;gt;
            &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"&amp;gt;&amp;lt;/script&amp;gt;
    &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;This will show the form to the user to upload the files. The form in this view template is pointing to a route named &lt;code&gt;files.store&lt;/code&gt; that we created earlier in &lt;code&gt;routes/web.php&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lQuV-tq5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sl3omphhlp1cty6y2c7i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lQuV-tq5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sl3omphhlp1cty6y2c7i.png" alt="Laravel upload form" width="880" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This is it for this tutorial.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you need more information regarding the package used you can read more below:&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/erlandmuchasaj"&gt;
        erlandmuchasaj
      &lt;/a&gt; / &lt;a href="https://github.com/erlandmuchasaj/laravel-file-uploader"&gt;
        laravel-file-uploader
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A simple, yet powerful Laravel  file uploader package
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Laravel File Uploader&lt;/h1&gt;
&lt;p&gt;Laravel File Uploader offers an easy way to upload files to different disks
The main purpose of the package is to remove the repeated and cumbersome code and simplify it into some simple methods.&lt;/p&gt;
&lt;h2&gt;
Installation&lt;/h2&gt;
&lt;p&gt;You can install the package via composer:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;composer require erlandmuchasaj/laravel-file-uploader&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
Usage&lt;/h2&gt;
&lt;p&gt;This package has an very easy and straight-forward usage
Just import the package and pass the file as parameter, and it will handle the rest.&lt;/p&gt;
&lt;div class="highlight highlight-text-html-php notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-k"&gt;use&lt;/span&gt; &lt;span class="pl-v"&gt;ErlandMuchasaj&lt;/span&gt;\&lt;span class="pl-v"&gt;LaravelFileUploader&lt;/span&gt;\&lt;span class="pl-v"&gt;FileUploader&lt;/span&gt;
&lt;span class="pl-v"&gt;Route&lt;/span&gt;::&lt;span class="pl-en"&gt;post&lt;/span&gt;(&lt;span class="pl-s"&gt;'/files'&lt;/span&gt;, &lt;span class="pl-k"&gt;function&lt;/span&gt; (&lt;span class="pl-smi"&gt;&lt;span class="pl-smi"&gt;\&lt;span class="pl-v"&gt;Illuminate&lt;/span&gt;\&lt;span class="pl-v"&gt;Http&lt;/span&gt;\&lt;span class="pl-v"&gt;Request&lt;/span&gt;&lt;/span&gt;&lt;/span&gt; &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;request&lt;/span&gt;) {

    &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;max_size&lt;/span&gt; = (&lt;span class="pl-smi"&gt;int&lt;/span&gt;) ini_get(&lt;span class="pl-s"&gt;'upload_max_filesize'&lt;/span&gt;) * &lt;span class="pl-c1"&gt;1000&lt;/span&gt;;
    
    &lt;span class="pl-c"&gt;// FileUploader::images() get all image extensions ex: jpg, png, jpeg, gif, etc.&lt;/span&gt;
    &lt;span class="pl-c"&gt;// FileUploader::documents() get all documents extensions ex: 'csv', 'html', 'pdf', 'doc', 'docx', 'ppt' etc.&lt;/span&gt;
    &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;extensions&lt;/span&gt; = implode(&lt;span class="pl-s"&gt;','&lt;/span&gt;, &lt;span class="pl-v"&gt;FileUploader&lt;/span&gt;::&lt;span class="pl-en"&gt;images&lt;/span&gt;());

    &lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;request&lt;/span&gt;-&amp;gt;&lt;/pre&gt;…
&lt;/div&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/erlandmuchasaj/laravel-file-uploader"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;



&lt;h2&gt;
  
  
  Was it helpful?
&lt;/h2&gt;

&lt;p&gt;Let me know in the comment section below if you ever use this package in any of your projects.&lt;/p&gt;

&lt;p&gt;Don’t forget to &lt;em&gt;like&lt;/em&gt; and &lt;em&gt;comment&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Follow &lt;a href="https://twitter.com/muchasaj"&gt;me&lt;/a&gt; for more web development tips, new packages and more.&lt;/p&gt;

&lt;p&gt;Thanks for reading.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>fileupload</category>
      <category>package</category>
    </item>
    <item>
      <title>PHP Sanitizer.</title>
      <dc:creator>Erland Muchasaj</dc:creator>
      <pubDate>Tue, 07 Mar 2023 08:40:00 +0000</pubDate>
      <link>https://forem.com/erlandmuchasaj/php-sanitizer-25fb</link>
      <guid>https://forem.com/erlandmuchasaj/php-sanitizer-25fb</guid>
      <description>&lt;p&gt;On the new year's eve, I set out to build some open source packages for &lt;a href="https://www.php.net/"&gt;PHP&lt;/a&gt; and &lt;a href="https://laravel.com/"&gt;Laravel &lt;/a&gt; community which is one of the best communities you can find. The packages would consist of libraries, utils, helpers and packages and also some starters for medium and large-scale projects.&lt;/p&gt;

&lt;p&gt;I have been working with PHP and related technologies for over a decade now and more often than not, I find myself using the same peace of code in different projects.&lt;/p&gt;

&lt;p&gt;Up until now I used to create Libraries which I would just transfer files from one project to another and reuse the library, but I wanted something more manageable and if I wanted to change something or fix issues to easily fix it in one place.&lt;/p&gt;

&lt;h2&gt;
  
  
  Backstory
&lt;/h2&gt;

&lt;p&gt;In my early days in programming, I often had to create search pages using vanilla PHP. &lt;br&gt;
This means I needed to get user input, parse it, sanitize it, and prepare for the query. &lt;br&gt;
Another thing to consider was special characters for different languages for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;э =&amp;gt; e
Ë =&amp;gt; e
Ç =&amp;gt; c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;For this reason I build a &lt;a href="https://github.com/erlandmuchasaj/sanitize"&gt;PHP Sanitizer&lt;/a&gt; class to only do just that. Sanitize user input and prepare it for SQL search queries.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--566lAguM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/erlandmuchasaj"&gt;
        erlandmuchasaj
      &lt;/a&gt; / &lt;a href="https://github.com/erlandmuchasaj/sanitize"&gt;
        sanitize
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A package to sanitize your input.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
PHP sanitize&lt;/h1&gt;
&lt;p&gt;This is a PHP package that helps to sanitize your input when performing search queries to DB
It cleans the input from all malicious characters.&lt;/p&gt;
&lt;h2&gt;
Installation&lt;/h2&gt;
&lt;p&gt;You can install the package via composer:&lt;/p&gt;
&lt;div class="highlight highlight-source-shell notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;composer require erlandmuchasaj/sanitize&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
Usage&lt;/h2&gt;
&lt;p&gt;Sanitize library offers a sanitize method that takes a parameter a dirty string parameter and return a cleaned string.&lt;/p&gt;
&lt;div class="highlight highlight-text-html-php notranslate position-relative overflow-auto js-code-highlight"&gt;
&lt;pre&gt;&lt;span class="pl-k"&gt;use&lt;/span&gt; &lt;span class="pl-v"&gt;ErlandMuchasaj&lt;/span&gt;\&lt;span class="pl-v"&gt;Sanitize&lt;/span&gt;\&lt;span class="pl-v"&gt;Sanitize&lt;/span&gt;;

&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;dirtyString&lt;/span&gt; = &lt;span class="pl-s"&gt;'Hello - World'&lt;/span&gt;;

&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;sanitizedString&lt;/span&gt; = &lt;span class="pl-v"&gt;Sanitize&lt;/span&gt;::&lt;span class="pl-en"&gt;sanitize&lt;/span&gt;(&lt;span class="pl-s1"&gt;&lt;span class="pl-c1"&gt;$&lt;/span&gt;dirtyString&lt;/span&gt;);

&lt;span class="pl-c"&gt;// do something with the sanitized text&lt;/span&gt;
&lt;span class="pl-c"&gt;// you can: $words = explode(' ', $sanitizedString);&lt;/span&gt;
&lt;span class="pl-c"&gt;// and search the DB per each word.&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
Support me&lt;/h2&gt;
&lt;p&gt;I invest a lot of time and resources into creating &lt;a href="https://github.com/erlandmuchasaj?tab=repositories"&gt;best in class open source packages&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you found this package helpful you can show support by clicking on the following button below and donating some amount to help me work on…&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/erlandmuchasaj/sanitize"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;br&gt;&lt;br&gt;
It is very simple to use. I will do a follow up with some examples of how to use it on your projects.&lt;/p&gt;

&lt;p&gt;Let me know in the comment section below if you ever use it in any of your projects.&lt;br&gt;
Don't forget to like and comment.&lt;br&gt;
Follow &lt;a href="https://twitter.com/muchasaj"&gt;me&lt;/a&gt; for more web development tips, new packages and more.&lt;br&gt;
Thanks for reading.&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>sanitize</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
