简体   繁体   English

ErrorException 数组到 Controller 文件中的字符串转换

[英]ErrorException Array to string conversion in Controller file

Hello guys please I'm having this laravel error in my controller and I need help大家好,我的 controller 出现此 laravel 错误,我需要帮助

Here's my controller这是我的 controller

        public function expectingpost(Request $request)
            {

                DB::table('expectings') ->insert([

                    $validatedData = $request->validate([
                        "time" => 'required|date_format:H:i',
                        "day" => 'required|date_format:Y-m-d',
                        "name" => 'required'
                    ]).

                    "time" => $request->time,
                    "day" => $request->date,
                   "name" => $request->name
                ]);

                return back() -> with('expecting', $request->input('name') . ' has been added as your guest');
            }
        }

PLease guys I seriously need fast responses because this has kept me on deck for long.请大家,我真的需要快速响应,因为这让我在甲板上待了很长时间。 Thank you谢谢

You shouldn't validate your data inside your insert, this should be first validating your data, then use it to create your model.您不应该在插入中验证您的数据,这应该首先验证您的数据,然后使用它来创建您的 model。 Another improvement use Eloquent models, there is no reason not to if you are just starting out.另一个改进是使用 Eloquent 型号,如果您刚刚起步,没有理由不这样做。

public function expectingpost(Request $request)
{
    $validatedData = $request->validate([
        'time' => 'required|date_format:H:i',
        'day' => 'required|date_format:Y-m-d',
        'name' => 'required'
    ]).

    Expecting::create($validatedData);

    return back()->with('expecting', $validatedData['name'] . ' has been added as your guest');
}

The Eloquent Model you need.您需要的 Eloquent Model。

use Illuminate\Database\Eloquent\Model;

class Expecting extends Model {
    protected $fillable = ['time', 'day', 'name'];
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ErrorException 数组到字符串的转换 Laravel 8 - ErrorException Array to string conversion Laravel 8 ErrorException:PHP中的数组到字符串的转换 - ErrorException : Array to string conversion in PHP 迁移--seed时将ErrorException数组转换为字符串 - ErrorException array to string conversion on migrate --seed ErrorException [注意]:数组到字符串转换PHP表单 - ErrorException [Notice]:Array to string conversion PHP Form 提交表单时出现“ErrorException 数组到字符串的转换” - "ErrorException Array to string conversion" when submitting a form PHP公告– yii \\ base \\ ErrorException(数组到字符串的转换)Yii - PHP Notice – yii\base\ErrorException (Array to string conversion) Yii 在 laravel 中上传图像时数组到字符串转换 ErrorException - Array to string conversion ErrorException while uploading image in laravel 7 ErrorException:数组到字符串的转换。 尝试在 hasMany 关系上创建 Many() 时 - ErrorException: Array to string conversion. When trying to createMany() on a hasMany relationship 带有转发器字段的 Laravel 表单提交中的 ErrorException 数组到字符串转换 - ErrorException Array to string conversion in Laravel form submission with repeater fields ErrorException 数组到字符串的转换 Laravel - 将 JSON 导入到 MySQL - ErrorException Array to string conversion Laravel - Importing JSON to MySQL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM