Laravel 5.1 form submission data (including arrays) Insert Database error Resolution

Source: Internet
Author: User

When the form has to submit an array to the database, such as to add some customer service QQ information, Laravel will throw the input field can not be an array of errors, the solution is also very simple.

Add more QQ customer service needs to use the array

Thrown error

    1. Errorexception in helpers.php line 671:preg_replace (): Parameter mismatch, pattern was a string while replacement was an arr Ay
Copy Code

Workaround:

In the model, the fields that need to be submitted are "blocked", received separately with input in the controller and serialized, and then saved.

Model Examples:

    1. Class Shop extends Model
    2. {
    3. Public $timestamps =false;
    4. protected $guarded = [' QQ ', ' submit '];
    5. }
Copy Code

Controller Example

    1. Public function Store (checknamerequest $request)
    2. {
    3. $shop = Shop::create (Input::get ());
    4. $shop->qq = serialize (Input::get (' QQ '));
    5. $shop->save ();
    6. }
Copy Code

In the same vein, it can be deserialized when displayed.

Original address: HTTP://NOTE.MANGO.IM/ARTICLE/24

Workaround, Laravel
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.