Connect with us

Laravel 6.5.2 Released this week for bug fix

kizinho

Published

on

Follow
Laravel 6.5.2 Released this week for bug fix
Photo: Naijacrawl

The Laravel team released v6. 5.2 this week—this version is a patch version release, containing mostly changes and fixes.

Here’s a few things of note:

  • If you’re using PostGIS types in Postgres, Laravel now supports a separation between geometry and geography types.
  • The BelongsToMany::cursor() method, now hydrates pivot relations.
  • Model serialization on jobs allows typed properties.

You can see the full list of new features and updates below and the whole diff between 6.5.1 and 6.5.2 on GitHub. The full release notes for Laravel 6.0 are available in the GitHub v6 changelog:

v6.5.2

Added

  • Allowed model serialization on jobs for typed properties (#30604, #30605, 920c364)
  • Allowed fallback when facade root accessor has previously been resolved (#30616)
  • Added support for separation between geometry and geography types for Postgres (#30545)
  • Added createWithContent() method to Illuminate\Http\Testing\File and Illuminate\Http\Testing\FileFactory (2cc6fa3, 181db51)

Refactoring

  • Improved PostgresGrammar::formatPostGisType() method readability (#30593)

Changed

  • Added symfony/debug dependency to illuminate/pipeline (#30611)
  • Override BelongsToMany::cursor() to hydrate pivot relations (#30580)
  • Ignore Redis prefix when verifying channel access in RedisBroadcaster (#30597, d77ce36)




kizinho

I am a software developer, like meeting people and love blogging, that's why I developed naijacrawl because that's what I love doing.

Continue Reading
Click To Comment

BE First To Comment


    Leave a Reply

    Your email address will not be published. Required fields are marked *

    Laravel 7 comes with Easy Implicit Route Model Binding

    kizinho

    Published

    on

    Laravel 7 comes with Easy Implicit Route Model Binding
    Photo: Naijacrawl

    Laravel 7 will be out 2020 with new awesome features. You can clean the way routing is been done with one line of code.

    But you can try the dev version by running this code

    laravel new example --dev
    


    In laravel 7 you can bind routes like this:


    Route::get('/posts/{post:slug}', function (Post $post) {
        // ...
    });
    
    


    Currently, Laravel 6 and below requires you to define a getRouteKeyName() method on the model like so:

    <?php
    
    class Post extends Model
    {
        /**
         * Get the route key for the model.
         *
         * @return string
         */
        public function getRouteKeyName()
        {
            return 'slug';
        }
    }
    


    You can use the below route binding when you have multiple routes that you want to bind differently.

    For example, the frontend route uses slugs to display posts and backend admin uses ids to manage posts:


    Route::get('/posts/{post:slug}', function (Post $post) {
        // ...
    });
    
    // Or you could use the default `{post}` here...
    Route::get('/admin/posts/{post:id}/edit', function (Post $post) {
        // ...
    });
    


    Thanks for reading.



    Continue Reading

    How to Automate App Setup with Laravel Initializer

    kizinho

    Published

    on

    How to Automate App Setup with Laravel Initializer
    Photo: Naijacrawl

    Have you ever found yourself writing multiple manual steps to set up a Laravel application in a new environment? Laravel Initializer is a convenient way to automate installing and updating a Laravel application:

    Laravel Initializer gives you the ability to declare multiple processes and run them with app:install and app:update artisan commands, which run predefined actions chain depending on the current environment.

    The app:install and app:update commands use two distinct classes that run commands based on a given environment. First, the install command uses the App\Install class:

    namespace App;
    
    use MadWeb\Initializer\Contracts\Runner;
    
    class Install
    {
        public function production(Runner $run)
        {
            return $run
                ->external('composer', 'install', '--no-dev', '--prefer-dist', '--optimize-autoloader')
                ->artisan('key:generate')
                ->artisan('migrate', ['--force' => true])
                ->artisan('storage:link')
                ->external('npm', 'install', '--production')
                ->external('npm', 'run', 'production')
                ->artisan('route:cache')
                ->artisan('config:cache')
                ->artisan('event:cache');
        }
    
        public function local(Runner $run)
        {
            return $run
                ->external('composer', 'install')
                ->artisan('key:generate')
                ->artisan('migrate')
                ->artisan('storage:link')
                ->external('npm', 'install')
                ->external('npm', 'run', 'development');
        }
    }
    
    

    The app:update command looks similar, using an App\Update class:

    namespace App;
    
    use MadWeb\Initializer\Contracts\Runner;
    
    class Update
    {
        public function production(Runner $run)
        {
            return $run
                ->external('composer', 'install', '--no-dev', '--prefer-dist', '--optimize-autoloader')
                ->external('npm', 'install', '--production')
                ->external('npm', 'run', 'production')
                ->artisan('route:cache')
                ->artisan('config:cache')
                ->artisan('event:cache')
                ->artisan('migrate', ['--force' => true])
                ->artisan('cache:clear')
                ->artisan('queue:restart'); ->artisan('horizon:terminate');
        }
    
        public function local(Runner $run)
        {
            return $run
                ->external('composer', 'install')
                ->external('npm', 'install')
                ->external('npm', 'run', 'development')
                ->artisan('migrate')
                ->artisan('cache:clear');
        }
    }
    
    

    You can also inject dependencies from the service container if you need to access services while running commands.

    This package contains a variety of runner actions you should check out in the readme. I found the MakeCronTask dispatch interesting:

    $run->dispatch(new \MadWeb\Initializer\Jobs\MakeCronTask)
    
    

    MakeCronTask adds the following to the server’s crontab list:

    * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
    
    

    You can do other things like creating a supervisord config for a typical queue worker or horizon.

    You can learn more about this package, get full installation instructions, and view the source code on GitHub at mad-web/laravel-initializer.

    Continue Reading

    How to convert image from png, jpg to webp image in Laravel

    kizinho

    Published

    on

    How to convert image from png, jpg to webp image in Laravel
    Photo: Naijacrawl

    Hi, folks will show how you can convert any image to webp image.

    Why Webp

    WebP is making headway in the image format space this year. The image format — which is developed by Google — uses both lossy and lossless compression by utilizing technology that Google purchased from On2 Technologies.


    WebP has been around a while now, actually, and it first made headlines in a 2010 Google press conference. But, like any new technology, it had some initial rough patches. Today, WebP is on version 1.0.0, so we thought it would be a great time to talk about what makes WebP so powerful, and why it’s a fantastic option for web designers and developers.


    Before I proceed to describe what WebP actually is, let us focus on why it matters—it’s not only about making images smaller, but it’s also about why and how the images need to be made smaller.


    You may have heard about design mistakes killing your SEO and conversion rates. While there are some aspects that CSS or JavaScript are responsible for, like blocking rendering, the images nowadays are a huge part of any website’s weight. Therefore, users on slower connections will have trouble interacting with your website (unless it’s an AMP).

    Just recently, It’s an interesting area of expertise, where you take care of lots of small things to deliver one big thing—a superfast, superlight website that reads on any device and looks amazing at the same time.


    Chances are, you’ve seen WebP images before. If you open Naijacrawl in Google Chrome, all of those thumbnails are going to be WebP thumbnails. If you were to open the Facebook app on your android phone, all of the images that you see would be WebP. It’s definitely being utilized by various companies around the world to increase performance.


    So let's see how you can do the same using laravel to convert your images to webp image.


    Note this works in all laravel versions


    I assumed you have a project already or you can create one by using this command


    composer create-project laravel/laravel webimage --prefer-dist


    You must have installed a composer before you can run the command.


    We need a controller so let's create one

    php artisan make:controller ImageWebpController
    


    Inside the controller, we will write a code that will process our image and convert it to webp inside a folder


    What it Requires

    file extension

    file name

    folder

    <?phpnamespace App\Http\Controllers;
    
    
    use Illuminate\Http\Request;
    use Illuminate\Support\Str;
    
    
    class ImageWebpController extends Controller {
    
    
        public function webpImage(Request $request) {
            if ($request->hasFile('file')) {
                $file = $request->file('file');
                $extension = $file->getClientOriginalExtension();
                $rand = '-' . strtolower(Str::random(10));
                $name = $rand . '.' . $extension;
                return $this->processImage($file, $name);
            }
        }
    
    
        private function processImage($file, $name) {
            $file->move(public_path('/test/image'), $name);
            //convert to webp 
            $webp = public_path() . '/test/image/' . $name;
            $im = imagecreatefromstring(file_get_contents($webp));
            $new_webp = preg_replace('"\.(jpg|jpeg|png|webp)$"', '.webp', $webp);
            imagewebp($im, $new_webp, 50);
            return [
                'message' => 'image successfully converted to webp. check your folder to see it'
            ];
        }
    
    
    }
    
    
    

    from what i did, i check if the request is a file before proceeding , have to get extension of the file and use it make a slug name for the image, because i don't want it to carry original name.

    $extension = $file->getClientOriginalExtension();
    

    I have to use str function to form a characters for the name of the image

     $rand = '-' . strtolower(Str::random(10));
    //final 
    name$name = $rand . '.' . $extension;
    

    I needed another private function because i want to separate my code for easy to read using processImage function.

     private function processImage($file, $name) {
            $file->move(public_path('/test/image'), $name);
            //convert to webp 
            $webp = public_path() . '/test/image/' . $name;
            $im = imagecreatefromstring(file_get_contents($webp));
            $new_webp = preg_replace('"\.(jpg|jpeg|png|webp)$"', '.webp', $webp);
            imagewebp($im, $new_webp, 50);
            return [
                'message' => 'image successfully converted to webp. check your folder to see it'
            ];
        }
    

    After i called it to the main function which is webpImage function .

    Inside processImage function , the file is moved to my public folder called test/image before converting it to webp image

    //get image that we want toconvert 
    $webp = public_path() . '/test/image/' . $name;
    //create the image       
     $im = imagecreatefromstring(file_get_contents($webp));
    //accept image extensions of jpg,png,webp 
    $im = imagecreatefromstring(file_get_contents($webp));        
    $new_webp = preg_replace('"\.(jpg|jpeg|png|webp)$"', '.webp', $webp);
    //make the webp image and set the quality to 50 //the more quality the more it becomes broght and increase mb// you can set to 100 which means no quality will be reduced        
    imagewebp($im, $new_webp,50);
    

    From my code i didn't add validation rule which you can do it if you needed it , just to make it allow only files and extension type


    Find this article helpful kindly share it.

    Continue Reading

    Latest



    Face of Naijacrawl


    ChukwubuikemSunday ChukwubuikemSunday

    Sunday Chukwubuikem


    Higher - 09061773292

    Trending