Add some changes
This commit is contained in:
39
app/Repos/Order/Loan/LoanOrderRepo.php
Normal file
39
app/Repos/Order/Loan/LoanOrderRepo.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repos\Order\Loan;
|
||||
|
||||
use App\Models\Branch\Branch;
|
||||
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
|
||||
*
|
||||
* @param App\Models\Order\Loan\LoanOrder $model
|
||||
*/
|
||||
public static function fillUniqueId($model): string
|
||||
{
|
||||
return sprintf('TB%s-%s', Branch::find($model->branch_id)->unique_code, $model->id) ?? uniqid();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user