New In Laravel 7 - e06 - Route Model Binding Improvements

Поделиться
HTML-код
  • Опубликовано: 3 июл 2024
  • Route Model Binding is one of the coolest and most used features of Laravel. Laravel 7 comes with some welcomed changes which include the new key customization and automatic scoping in nested routes. Let's take a look at some concrete example of how it works.
    Foreign Devs Podcast
    foreign-devs.transistor.fm/su...
    Documentation
    laravel.com/docs/master/routi...
    For the best experience, follow along in our interactive school at www.coderstape.com
    DigitalOcean Referral
    m.do.co/c/7dce5364ef4d
    It's that time of the year again when we get new fresh features in Laravel. Let's explore what is coming to the latest version of Laravel.

Комментарии • 45

  • @1mr4n4li
    @1mr4n4li 4 года назад +3

    please start a series on any famous ecommerce laravel package

  • @mel-182
    @mel-182 4 года назад

    thanks victor!!! this is really awesome feature!

  • @shamshershikalgar
    @shamshershikalgar 4 года назад +1

    Thanks for making this video

  • @walidbagh
    @walidbagh 4 года назад +1

    My most awaited feature :D

  • @Stoney_Eagle
    @Stoney_Eagle 4 года назад +1

    Dynamic view without a controller... Magic 💫😱😍

  • @fernandocamilopro
    @fernandocamilopro 4 года назад +1

    thx brother! love laravel!!!

  • @jayedkhan1903
    @jayedkhan1903 4 года назад +2

    you are one the best explainer. always loved your content. if you can please upload a video about larvel 6 to 7 upgrade guide

  • @MyNguyen-xb1gv
    @MyNguyen-xb1gv 2 года назад

    Thank you!

  • @mahirinyeri
    @mahirinyeri 2 года назад

    Thanks 👍

  • @abelenocrodriguez
    @abelenocrodriguez 4 года назад +4

    Good video Bro, you should do one that says 50 tricks with laravel

  • @msdmansory
    @msdmansory 4 года назад

    tanx 🙏 ❤

  • @pyongits
    @pyongits 4 года назад

    Your great man ❤

  • @kapa4208
    @kapa4208 4 года назад +5

    Hi Victor! Would you do any tutorial on how to build SPA with Laravel, Vue, and Inertia.js?

  • @freecourse1842
    @freecourse1842 4 года назад

    THANKS

  • @Adbal99
    @Adbal99 4 года назад

    I was actually thinking how to put a slug in my laravel 6 project and this makes me to finally update my laravel version :D

    • @lucassnel9064
      @lucassnel9064 4 года назад

      You don't need to upgrade to do that, he showed you the old method in the video.

    • @Adbal99
      @Adbal99 4 года назад

      @@lucassnel9064 oh, thanks buddy

  • @kmtsvetanov
    @kmtsvetanov 4 года назад

    Oh wow... This is definitely going to be helpful. Thank you!
    One question: what if we have /user/1/post/2/comment/3 (all have in the route ":id") ?
    It will be "comment" for that "port" for that "user"?
    Is there a way to make it another level up like:
    Get the "comment" for that "post" for thet "user" AND the "comment" has to be from that "user"

  • @sergeyz4591
    @sergeyz4591 4 года назад

    I love Laravel, I really love it and hate at the same time !!!

  • @someguytu
    @someguytu 4 года назад

    Thanks this is awesome. Who would you handle something like Catgory/subcategory/subcategory/...... I think this is also real when i can have lets say /category2/subcategory wit the same name as category1. However i cant figure out how to next more subcategories.

  • @KristofNachtergaele
    @KristofNachtergaele 4 года назад

    This is going to be really useful for what i'm working on now. Are you planning to release a video on how to do upgrades from v6 to v7?

    • @CodersTape
      @CodersTape  4 года назад +1

      I don't think it will be too complicated of an upgrade since there aren't any deprecations that I can think of

    • @KristofNachtergaele
      @KristofNachtergaele 4 года назад

      @@CodersTape I've only started looking at Laravel a week ago and didn't realise that a new version was coming out. I'd also need to look into how to update a project to a more recent version in the same main version.

  • @mokhosh
    @mokhosh 4 года назад +1

    What would the protection do if the column in the posts table was `author_id`?

    • @asathler
      @asathler 3 года назад +1

      Laravel will check models relatioship, wherever the field you need.
      ```
      return $this->belongsTo(User::class, 'author_id');
      ```

  • @efai
    @efai 4 года назад

    so if I want to pull id with slug, not just id or slug, I must use {post:id}-{post:slug} ?

  • @sushanshresthadxs
    @sushanshresthadxs 4 года назад

    do the airlock please :D

  • @eugenesidelnyk4600
    @eugenesidelnyk4600 4 года назад

    How to customize model binding in resource controller?

  • @turagoda
    @turagoda 4 года назад

    How does the model binding work for resource controller with nested multiple parameters ?
    Example:
    localhost/users/1/posts/2/comments/3
    ( where 'posts' table has 'user_id' foreign key and 'comments' table has 'post_id' foreign key )
    Using:
    Route::resource('users.posts.comments', 'BlogController');
    instead of doing:
    Route::name('users.posts.comments.index')->get('users/{user}/posts/{post:id}/comments', 'BlogController@index');
    Route::name('users.posts.comments.create')->get('users/{user}/posts/{post:id}/comments/create', 'BlogController@create');
    Route::name('users.posts.comments.show')->get('users/{user}/posts/{post:id}/comments/{comment:id}', 'BlogController@show');
    Route::name('users.posts.comments.edit')->get('users/{user}/posts/{post:id}/comments/{comment:id}/edit', 'BlogController@edit');
    Route::name('users.posts.comments.update')->patch('users/{user}/posts/{post:id}/comments/{comment:id}/update', 'BlogController@update');
    Route::name('users.posts.comments.store')->post('users/{user}/posts/{post:id}/comments', 'BlogController@store');
    Route::name('users.posts.comments.destroy')->delete('users/{user}/posts/{post:id}/comments/{comment:id}', 'BlogController@destroy');

  • @shameulzion9221
    @shameulzion9221 3 года назад

    How to use specify key name in resource route???

  • @zMULDERz
    @zMULDERz 4 года назад

    Very strange., its doesn't work for me!
    Route::get('/person/{name}','PersonSiteController@show');
    And in dump don`t choose id, I see only dump of instance. Do any one know what a problem?

  • @ExpDev69
    @ExpDev69 4 года назад

    Is the protection thing a bug? Or is it because the ID is unique to each post, but slugs aren't necessarily? So for example, "/users/1/posts/a-cool-post" and "/users/2/posts/a-cool-post" are two completely different posts.

    • @CodersTape
      @CodersTape  4 года назад

      when you are using slugs as keys, you must have unique constraint on that column, otherwise, you are right. If slugs can be repeated than it can't be used as a substitute for a unique identifier.

  • @Virtualmix
    @Virtualmix 4 года назад

    Thanks for the video as always.
    I'm not sure what we're gaining here, it looks like another way to do something we could already very easily do with getRouteKeyName().
    What if we use the Route::resource method? Looks like it wouldn't work and would require to use the getRouteKeyName() method anyway...
    Also not sure about the extra protection added to the route model binding; I feel like this authorization logic belongs in a Policy. That could be confusing to debug IMHO.

    • @lucassnel9064
      @lucassnel9064 4 года назад +1

      The benefit is that for example the user-end you want to bind posts based on slug, but in the admin panel you might want to bind on ID. So this way it's on a per-route basis instead of globally set once in the model.

    • @Virtualmix
      @Virtualmix 4 года назад

      @@lucassnel9064 I didn't think about that. Thank you for the explanation 👍

  • @aqshalzakki2526
    @aqshalzakki2526 4 года назад

    what if my slug is not in the database, iam getting not found since i dont have slug field and im using accessor, solution please?

  • @julienSibille
    @julienSibille 4 года назад

    Why is the default with mandatory id ? I mean, the binding concept is that i don't have to tell to Laravel look at the post id

    • @specialist7625
      @specialist7625 4 года назад

      Because the default of $primaryKey on base model is 'id', You can override it on your model.

    • @CodersTape
      @CodersTape  4 года назад

      I think that that automatic scoping has the potential to break some code in existing projects so adding that "opt in" feature will ensure it is 100% backwards compatible. Imagine that you didn't want that scoping, then there would be no way to "opt out"

    • @julienSibille
      @julienSibille 4 года назад

      @@CodersTape Ok, it's just compatibility stuff so. Thank you

  • @msdmansory
    @msdmansory 4 года назад

    Please insert nex video 🙏❤

  • @Knee-Lew
    @Knee-Lew 4 года назад

    So now Laravel 7 is optimized for blog development (I assumed)?
    But yeah, hidden product listing details owned by a seller could be useful too.

  • @xevinavarro2196
    @xevinavarro2196 4 года назад

    wokeh?

  • @rognales
    @rognales 4 года назад

    That caveat is too big to ignore yet too small to overlook