Connect with us

Laravel 7 comes with Easy Implicit Route Model Binding

kizinho

Published

on

Follow
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.





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 *

    How to Download Instagram Photo and Video using PHP (easy way)

    kizinho

    Published

    on

    How to Download Instagram Photo and Video using PHP (easy way)
    Photo: Naijacrawl

    Hi folks, this script is really cool for those of you that want to get informations like photos and videos from Instagram, this tool is for you.

     

    Assuming you are working on a project that needs to get data from Instagram just follow these steps and get it done.

     

    Step 1 

    Download this package using the following command 

     

    composer require ayesh/instagram-download

     

    Step 2 

     

    Set your Instagram photo or video URLs as show below 

     

    getDownloadUrl(); // Returns the download URL.
      $type = $client->getType(); // Returns "image" or "video" depending on the media type.
    }
    catch (\InvalidArgumentException $exception) {
      /*
       * \InvalidArgumentException exceptions will be thrown if there is a validation 
       * error in the URL. You might want to break the code flow and report the error 
       * to your form handler at this point.
       */
      $error = $exception->getMessage();
    }
    catch (\RuntimeException $exception) {
      /*
       * \RuntimeException exceptions will be thrown if the URL could not be 
       * fetched, parsed, or a media could not be extracted from the URL. 
       */
      $error = $exception->getMessage();
    }

     

    You are good to go.

     

     

    Features:

     

    1.Validates Instagram URL (domain validation, URL path validation).

     

    2.Uses OG properties to detect the image and video URL.

     

    3.Supports Instagram photos, videos, and Instagram TV videos Verbose error reporting with proper exceptions.

     

    4.Full unit tests No dependencies other than PHP curl extension (which is most likely enabled by already)

     

    This awesome script written by Ayesh, Visit their official github repository and follow for future updates.

     

    Demo

     

    Enjoy.

    Continue Reading

    Latest



    Face of Naijacrawl


    ChukwubuikemSunday ChukwubuikemSunday

    Sunday Chukwubuikem


    Higher - 09061773292

    Trending