Connect with us

Laravel 7 comes with Easy Implicit Route Model Binding

kizinho

Published

on

Follow
NEWS: Laravel 7 comes with Easy Implicit Route Model Binding [New  Developer] » Naijacrawl
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.



Click Here To Comment


site


kizinho

Adike Kizito is a top-rated software developer, blogger, sports, and entertainment lover. He is the CEO of these popular websites Naijacrawl.com and Mp3ager.com. He operates his software developing task through Kizzsoft.com,... Read More

Continue Reading
1 Comment

1 Comment

  1.  Timmortal

    Thanks for this amazing tutorial, kizhinho.
    There are so much i can take away from this and refractor some PHP that i have been working on, hope to see more from you soon.


Leave a Reply

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

How to Upgrade Laravel Application from Version 5 to latest Version 8

kizinho

Published

on

DEVELOPER PROGRAMMING: How to Upgrade Laravel Application from Version 5 to latest Version 8 [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Hi, Folks, have you feels like Laravel continuous released of new versions has let you down and you can't cope with it any longer, don't worry this article is a quick guide for you, that has I upgrade naijacrawl from 5.8 to the latest 8 versions.All you need to know before upgrading your old laravel.External packages might fail to install, so isolate your packages firstInstall fresh laravel applicationThank me later.First, all you will do to be successful when upgra...
Continue Reading

Laravel 8 is now released!

kizinho

Published

on

DEVELOPER PROGRAMMING: Laravel 8 is now released! [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Laravel 8 is now released and includes many new features including Laravel Jetstream, a models directory, model factory classes, migration squashing, rate-limiting improvements, time testing helpers, dynamic blade components, and many more features.Before we jump into the new features, we’d like to point out that starting with version 6, Laravel now follows semver and will release a new major version every six months. You can see how the release process works here.L...
Continue Reading

How to fix Flutterwave common error's while Integrating payment in your Laravel App

kizinho

Published

on

DEVELOPER PROGRAMMING: How to fix Flutterwave common error's while Integrating payment in your Laravel App [New  Developer Programming] » Naijacrawl
Photo: Naijacrawl
Hi folks, I was integrating FLutterwave on my laravel app, on the process i found a bunch of errors while trying to use it accept payment on my site. Have been a Paystack heavy user but decided to use Flutterwave for a reason that I love to do. Going through this article I will list the two types of error or bug that you must encounter while using Laravel Rave steps to get Flutterwave payment working.Types of errorError on the payment page when user try to refresh t...
Continue Reading

Latest


Download Naijacrawl App today

Fastest way to read on the go

Download the Naijacrawl App.