apply soft delete by custom laravel
Inside Migrations :
=====================
public function up()
{
Schema::create('users', function (Blueprint $table) {
.........
.........
$table->timestamp('deleted_at')->nullable();
...........
});
}
Inside Models :
=================
class User extends Authenticatable
{
..........
protected static function boot()
{
parent::boot();
static::addGlobalScope(new CustomSoftDeleteScope);
}
.......
}
Add a global scope file :
==========================
<?php
namespace App\Scopes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;
class CustomSoftDeleteScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$builder->whereNull('deleted_at');
}
}
Also in PHP:
- debug bar laravel print array
- convert timestamp to readable date and time
- download from laravel
- $testing_recipient_email_list = str_replace('@', "+{$recipient}@", $testing_recipient_email);
- db import laravel
- Allowed memory size of 1610612736 bytes exhausted (tried to allocate 4096 bytes) in phar://C:/Users/Public/composer.phar/src/Composer/DependencyResolver/Solver.php on line 223
- clear firebase cacheweb hosting
- 32 byte random string php
- PHP REDIRECTION
- catch an error php
- Seeding Laravel
- Use Laravel for server
- check if home page wordpress
- find char in string php
- array index exist php
- echo in json format php
- error_reporting( ~E_NOTICE )
- Upload image laravel 6
- clear cache locally laravel
- file_get_contents(): SSL: Network is down
- array unique php by value
- file_put_contents true php
- Malformed UTF-8 characters, possibly incorrectly encoded
- * in array key php