Laravel ErrorException 数组到字符串的转换
Laravel ErrorException Array to string conversion
我有一个联系表格,当我按 post 时,我注册了,但出现以下错误。
ErrorException
Array to string conversion
型号
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
protected $guarded = [];
protected $table = ['contact'];
}
控制器
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();
}
在您将 protected $table = ['contact'];
设置为数组的模型中,这应该是一个字符串,如下所示:
protected $table = 'contact';
请阅读文档https://laravel.com/docs/7.x/eloquent#eloquent-model-conventions
和 如果 你使用 Laravel 约定那么就不需要自己设置 $table
因为 Laravel 会猜名字基于模型名称。
我有一个联系表格,当我按 post 时,我注册了,但出现以下错误。
ErrorException
Array to string conversion
型号
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Contact extends Model
{
protected $guarded = [];
protected $table = ['contact'];
}
控制器
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();
}
在您将 protected $table = ['contact'];
设置为数组的模型中,这应该是一个字符串,如下所示:
protected $table = 'contact';
请阅读文档https://laravel.com/docs/7.x/eloquent#eloquent-model-conventions
和 如果 你使用 Laravel 约定那么就不需要自己设置 $table
因为 Laravel 会猜名字基于模型名称。