laravel与mongodb ErrorException(E_WARNING)array_flip()

时间:2019-04-06 10:42:12

标签: php

我想在模型中使用子填充数组

protected $fillable = [
    'requestInfo'=>[
        'companyname',
        'province',
        'district',
        'village',
        'phone',
    ],
    'owner'=>[
        'fullname',
        'province',
        'district',
        'village',
        'nationality',
        'fax',
        'phone',
        'factorynamela',
        'factorynameen',
        'located',
        'locatprovince',
        'locatdistrict',
        'locatvillage',
        'locatein'
    ],
];

但是有错误:

  

C:\ xampp \ htdocs \ mocbizrrequest \ blog \ vendor \ laravel \ framework \ src \ Illuminate \ Database \ Eloquent \ Concerns \ GuardsAttributes.php

    /**
     * Determine if the model is totally guarded.
     *
     * @return bool
     */
    public function totallyGuarded()
    {
        return count($this->getFillable()) == 0 && $this->getGuarded() == ['*'];
    }

    /**
     * Get the fillable attributes of a given array.
     *
     * @param  array  $attributes
     * @return array
     */
    protected function fillableFromArray(array $attributes)
    {
        if (count($this->getFillable()) > 0 && ! static::$unguarded) {
            return array_intersect_key($attributes, array_flip($this->getFillable()));
        }

        return $attributes;
    }
}

参数

"array_flip(): Can only flip STRING and INTEGER values!"
ErrorException (E_WARNING)
array_flip(): Can only flip STRING and INTEGER values!

请帮助我谢谢

我想在模型中使用子填充数组 在我的模型文件中

<?php
/**
 * Created by IntelliJ IDEA.
 * User: EXTRA
 * Date: 4/5/2019
 * Time: 11:48 AM
 */

namespace App\Model;
use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class RequestFrom extends Eloquent
{
    protected $connection = 'mongodb';

    protected $collection = 'requestForm';


    protected $fillable = [
        'requestInfo'=>[
            'companyname',
            'province',
            'district',
            'village',
            'phone',
        ],
        'owner'=>[
            'fullname',
            'province',
            'district',
            'village',
            'nationality',
            'fax',
            'phone',
            'factorynamela',
            'factorynameen',
            'located',
            'locatprovince',
            'locatdistrict',
            'locatvillage',
            'locatein'
        ],
    ];

在控制器文件中

namespace App\Http\Controllers;

use App\Model\RequestFrom;

use Illuminate\Http\Request;

class RequestFromController extends Controller
{
    public function index()

    {

        $requestForms = RequestFrom::all();

        return view('requestForm.index',compact('requestForms'))

            ->with('i', (request()->input('page', 1) - 1) * 5);

    }



    public function create()

    {

        return view('requestForm.create');

    }


    /**

     * Store a newly created resource in storage.

     *

     * @param  \Illuminate\Http\Request  $request

     * @return \Illuminate\Http\Response

     */

    public function store(Request $request)

    {

        request()->validate([
            'requestInfo'=>[
                'companyname' => 'required',
                'province' => 'required',
                'district' => 'required',
                'village' => 'required',
                'phone' => 'required'
            ],
            'owner'=>[
                'fullname' => 'required',
                'province' => 'required',
                'district' => 'required',
                'village' => 'required',
                'nationality' => 'required',
                'fax' => 'required',
                'phone' => 'required',
                'factorynamela' => 'required',
                'factorynameen' => 'required',
                'located' => 'required',
                'locatprovince' => 'required',
                'locatdistrict' => 'required',
                'locatvillage' => 'required',
                'locatein' => 'required'
            ],
        ]);
    RequestFrom::create($request->all());

        return redirect()->route('requestForm.index')

            ->with('success','created successfully.');

    }

0 个答案:

没有答案