39 lines
807 B
PHP
39 lines
807 B
PHP
<?php
|
|
|
|
namespace App\Repos\Order\Loan;
|
|
|
|
use App\Models\Branch\Branch;
|
|
use App\Repos\Order\OrderRepo;
|
|
use Closure;
|
|
|
|
class LoanOrderRepo
|
|
{
|
|
/**
|
|
* When model is being created
|
|
*/
|
|
public static function creating(): Closure
|
|
{
|
|
return function ($model) {
|
|
$model->status = $model->status ?: OrderRepo::defaultStatus();
|
|
};
|
|
}
|
|
|
|
/**
|
|
* When model is created
|
|
*/
|
|
public static function created(): Closure
|
|
{
|
|
return function ($model) {
|
|
$model->update(['unique_id' => static::fillUniqueId($model)]);
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Fill unique id
|
|
*/
|
|
public static function fillUniqueId($model): string
|
|
{
|
|
return sprintf('TB%s-%s', Branch::find($model->branch_id)->unique_code, $model->id) ?? uniqid();
|
|
}
|
|
}
|