"apply soft delete by custom laravel" Code Answer's
You're definitely familiar with the best coding language PHP that developers use to develop their projects and they get all their queries like "apply soft delete by custom laravel" answered properly. Developers are finding an appropriate answer about apply soft delete by custom laravel related to the PHP coding language. By visiting this online portal developers get answers concerning PHP codes question like apply soft delete by custom laravel. Enter your desired code related query in the search bar and get every piece of information about PHP code related question on apply soft delete by custom laravel.
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');
}
}
All those coders who are working on the PHP based application and are stuck on apply soft delete by custom laravel can get a collection of related answers to their query. Programmers need to enter their query on apply soft delete by custom laravel related to PHP code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about apply soft delete by custom laravel for the programmers working on PHP code while coding their module. Coders are also allowed to rectify already present answers of apply soft delete by custom laravel while working on the PHP language code. Developers can add up suggestions if they deem fit any other answer relating to "apply soft delete by custom laravel". Visit this developer's friendly online web community, CodeProZone, and get your queries like apply soft delete by custom laravel resolved professionally and stay updated to the latest PHP updates.