3 months ago

Add new row to model table

Posted 3 months ago by mirsahib

I am try to insert new item to Payment table Here is my Payment table

public function up()
        Schema::create('payments', function (Blueprint $table) {
            $table->string('comment')->default("Earum eligendi reprehenderit impedit eveniet. Omnis et optio voluptatem dolorum non.");

Here is my controller function

public function create(Request $request){
        $validateData = Validator::make($request->all(),[
            return response()->json(["message"=>$validateData->messages()], 404);
            $tenantRows = DB::select(DB::raw("SELECT COUNT(tenants.id) FROM tenants WHERE tenants.tenant_status=:status"),array('status'=>1));
            $tenantsId = DB::select(DB::raw("SELECT tenants.id FROM tenants WHERE tenants.tenant_status=:status"),array('status'=>1));
            foreach($tenantsId as $id){
                $payment = new Payment;
                $payment->tenant_id = $id;
                $payment->pay_month = $request->month;
                $payment->pay_year = $request->year;
            return response()->json('success');


I am getting the following error while inserting new row to the table

Object of class stdClass could not be converted to string

Please sign in or create an account to participate in this conversation.