• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Laravel - Implicit route model binding with soft deleted data

phplaravelrouteslaravel-5.2


PHP Snippet 1:

//Route Service Provider
 $router->bind('post', function($post)
     return Post::withTrashed()->where('id', $post)->firstOrFail();
});

// Controller
public function show(Post $post) {

// If the post has been trashed and the user is not admin, he cannot see it
     if (!Auth::user()->isAdmin() && $post->trashed())
         abort(404);

     // Proceed with normal request because the post has not been deleted.
}

PHP Snippet 2:

Route::get('posts/{post}', [PostController::class, 'show'])->withTrashed();

Related Snippets

SilverStripe unable to populate multiple member Childs

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

How to check user Permissions using Custom Middleware in Laravel

How to show selected value using javascript in laravel

Laravel 5.1 how to use {{ old('') }} helper on blade file for radio inputs

Laravel 5.1 Unknown database type enum requested

generating a random code in php?

Edit XML in HTML form and submit to self

How to run a shell as root from php (apache)

Laravel php artisan serve to mimic HTTPS

Inserting Country Selection into MySQL PHP [duplicate]

How to get monthly wise data in laravel

Laravel Nova Dependency Container what are the allowed resource properties other than id in dependsOn

how to pass row id in href of a tag in codeigniter controller?

Live search query using JS and PHP for QA forum

About Contact Privacy policy Terms and conditions