D
D
Dmitry2019-04-12 18:16:17
Laravel
Dmitry, 2019-04-12 18:16:17

Why are the last two values ​​not written to the database?

Hello Laravel site
In controller

app/Http/Controllers/Api/ProductCommentsController.php

in the store method I create a new comment. All data is saved and user_name and user_mail first gave an error, then made the default null and they are saved as null.
This returns a completely filled array
Separately, $request->get('userName')
and
$request->get('userEmail')
are also not empty
Thought the column name did not match, but everything matches
5cb0ab642d3bc949210095.png5cb0abbfaedbc438313271.png
public function store(Request $request)
    {
        $new_comment = [
            'product_slug' => $request->get('productSlug'),
            'product_id' => $request->get('productID'),
            'user_id' => $request->get('userID'),
            'content' => $request->get('content'),
            'user_name' => $request->get('userName'),
            'user_mail' => $request->get('userEmail'),
        ];

        $comment = new ProductComments($new_comment);
        $comment->save();

        return response()->json($new_comment);
    }

What could be the problem?
Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
JhaoDa, 2019-04-12
@ddimonn8080

https://laravel.com/docs/5.6/eloquent#mass-assignment

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question