1

I have a contact form and when I press the post, I register, but it gives the following error.

ErrorException
Array to string conversion

Model

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Contact extends Model
{
    protected $guarded = [];

    protected $table = ['contact'];
}

Controller

 public function contactpost(Request $request) {
        $contact = new Contact;
        $contact->name = $request->name;
        $contact->email = $request->email;
        $contact->topic = $request->topic;
        $contact->message = $request->message;
        $contact->save();
    }
3
  • What have you tried to debug the problem? Usually, such an error message contains the exact line and the file triggering the error Commented Jul 21, 2020 at 6:40
  • When I press a form on my contact page, I want to register the response I received via post to the database, but there is a problem. Commented Jul 21, 2020 at 6:42
  • Please add all clarification to your question by edting it. Additionally, add your debugging attempts and the full and exact error message Commented Jul 21, 2020 at 6:44

1 Answer 1

3

In the model you set the protected $table = ['contact']; to a array, this should be a string like so:

protected $table = 'contact';

Please read the docs https://laravel.com/docs/7.x/eloquent#eloquent-model-conventions

And if you use the Laravel conventions then there is no need to set the $table yourself as Laravel will guess the name based of the Model name.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.