PHPackages                             smashed-egg/laravel-auth-route-bindings - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. smashed-egg/laravel-auth-route-bindings

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

smashed-egg/laravel-auth-route-bindings
=======================================

Adds support for creating Route Model bindings to an authenticated user in Laravel

1.4.0(4mo ago)02.8kMITPHPPHP ^8.0.2CI passing

Since Jul 6Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/smashed-egg/laravel-auth-route-bindings)[ Packagist](https://packagist.org/packages/smashed-egg/laravel-auth-route-bindings)[ RSS](/packages/smashed-egg-laravel-auth-route-bindings/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (7)Versions (7)Used By (0)

 [![](https://raw.githubusercontent.com/smashed-egg/.github/05d922c99f1a3bddea88339064534566b941eca9/profile/main.jpg)](https://raw.githubusercontent.com/smashed-egg/.github/05d922c99f1a3bddea88339064534566b941eca9/profile/main.jpg)

Laravel Auth Route Bindings
===========================

[](#laravel-auth-route-bindings)

[![Latest Stable Version](https://camo.githubusercontent.com/50190a91bb06a9d8f51a56c577a8b0045b05decc5b5da1d928295dc5756857d1/68747470733a2f2f706f7365722e707567782e6f72672f736d61736865642d6567672f6c61726176656c2d617574682d726f7574652d62696e64696e67732f762f737461626c65)](https://github.com/smashed-egg/laravel-auth-route-bindings/releases)[![Downloads this Month](https://camo.githubusercontent.com/1939143697f835bd4fcb7d3641ea3f1aac31321b473681dc7c0988b2ec8723f4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f736d61736865642d6567672f6c61726176656c2d617574682d726f7574652d62696e64696e67732e737667)](https://packagist.org/packages/smashed-egg/laravel-auth-route-bindings)

This package allows you to create route model bindings that also use the authenticated user to retrieve the model.

For example. You might want to check that the Post model requested belongs to the User that's logged in. Previously you might have done something like the following:

```
Route::get('posts/{post}', function (Post $post) {
    abort_unless($post->user_id === auth()->user()->getAuthIdentifier());
    return $post;
});
```

or

```
Route::get('posts/{id}', function ($id) {
    $post = Post::where('user_id', auth()->user()->getAuthIdentifier())->findOrFail($id);
    return $post;
});
```

or using Policies:

```
