• 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

Laravel-fopen: failed to open stream: Permission denied

Unable to match results of php hash_hmac() and coldfusion hmac()

Twig - How to check if variable is a number / integer

auth pages not getting css in laravel

Laravel 5.2: Unable to locate factory with name [default]

How to create laravel storage symbolic link for production or sub domain system?

CSV to PHP class properties

Exact alternate to mcrypt_encrypt in PHP 7.2

PHP to search within txt file and echo the whole line

Add 2 Webcam in one page with WebcamJS

MySQL upgrade causing unexpected results on simple WHERE clauses

How to add automatically collapse/expand in content wordpress (single.php)?

Converting IPv6 to IPv4 address in PHP

Laravel excel maatwebsite 3.1 import, date column in excel cell returns as unknown format number. How to solve this?

Required field only if another field has a value, must be empty otherwise

About Contact Privacy policy Terms and conditions