mardi 20 septembre 2016

Create uniqueID based on id mysql laravel 5

I want to create uniqueID for column transid like autoincrement. but I already have a column id (autoincrement).

column transid should be 01000001 and autoincrement, or follow column id for the last number.

here is my code

public function insertFund($request,$lender, $ftype, $sign)
{
    $fmamt = str_replace(".","",$request->fmamt );
    $fdesc = $request->fdesc;
    $fdate = $request->fdate;
    $trnsfer  = $request->file('upload_trnsfer');         
    $transid = "01".str_pad($fund->id, 5, '0', STR_PAD_LEFT); 

    if($fdesc == null)
    {
        $fdesc = '';
    }
    $fund = $this->fund->create([
        'lender_id' => $lender->id,
        'transid' => $transid,
        'fmamt' => $fmamt,
        'refdc' => '',
        'ftype' => $ftype,
        'sign'  => $sign,
        'fdesc' => $fdesc,
        'fdate' => $fdate,
        'fstat' => 'pending'
    ]);
    return $fund;
}

I think, the core issue is here.

$transid = "01".str_pad($fund->id, 5, '0', STR_PAD_LEFT); 

How should I write code in for this? Thanks in Advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire