简体   繁体   中英

Data is not entered into the database mysql laravel 5

I used this code in my controller to insert data into fund table.

public function postInvestorTopup(Request $request)
{
    $user = $this->user->findOrFail(auth()->user()->id);
    $lender = $this->lender->whereUserId($user->id)->firstOrFail();
    $l_id = DB::table('lender')->where('user_id',$user->id)->first()->id;
    $inputList = $request->all();
    $investorTopup = array();
    foreach ($inputList as $key => $value) {
        if (strpos($key, 'fund') !== false){
            if($value != "")
            {
                $fund = new Fund;
                $fund->lender_id = $l_id;
                $fund->fmamt = $value;
                $fund->refdc = $value;
                $fund->ftype = '01';
                $fund->fdesc = $value;
                $fund->fstat = 'pending';
                $fund->fdate = $value;
                $fund->sign  = 'Debit';
                $fund->save();
                array_push($investorTopup, $fund);
            }
        }
    }
    foreach ($investorTopup as $fund){
        $fund->transid = date("ym").'03'.str_pad($fund->id, 5, '0', STR_PAD_LEFT);
        $fund->save();
    }

Am I have a mistake so that data is not entered into the database? thanks in advance for any help

Here in get method we are passing name of fields from where we input data Use this method to input data to DB

$user = new customer;

        $user ->name=input::get("name");
        $user ->email=input::get("email");
        $user ->country=input::get("country");
        $user ->gender=input::get("gender");

        $user->save();

Try this one hope it will help

I've found my solution by change my method

this is the 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 = date("ym")."01";      

    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'
    ]);

    $fund->transid = date("ym").'01'.str_pad($fund->id, 5, '0', STR_PAD_LEFT);                
    $fund->save();        
    return $fund;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM