gpt4 book ai didi

php - Laravel htmlspecialchars() 期望参数 1 是字符串,我的项目中给出的对象?

转载 作者:行者123 更新时间:2023-12-04 11:38:06 25 4
gpt4 key购买 nike

所以我正在尝试编写一个简单的网站表单。但它有这个 htmlspecialchars 错误。

我试图制作 {{ $message }} 但它没有用。有同样的错误。

这是我的 Controller :

<?php
namespace App\Http\Controllers;
use Mail;
use Illuminate\Http\Request;
class ContactMessageController extends Controller
{
public function create()
{
return view('form');
}

public function store(Request $request)
{
$this->validate($request, [
'name' => 'required',
'email' => 'required|email',
'address' => 'required',
]);

Mail::send('emails.contact-message', [
'message' => $request->message
], function($mail) use($request) {
$mail->from($request->email, $request->name);

$mail->to('john@example.com')->subject('Contact message');
});

return redirect()->back()->with('flash_message', 'thanks');
}
}

这是我的 Blade
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Customer Details</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" type="text/css" media="screen" href="main.css" />
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.0/css/bootstrap.min.css" integrity="sha384-PDle/QlgIONtM1aqA2Qemk5gPOE7wFq8+Em+G/hmo5Iq0CCmYZLv3fVRDJ4MMwEA" crossorigin="anonymous">
<style>
.invalid-feedback {
display: block;
}
</style>
</head>
<body>
<div class ="container">
<h1>Customer Form</h1>
@if (Session::has('flash_message'))
<div class="alert alert-success">{{ Session::get('flash_message') }}</div>
@endif
<form method="post" action="{{ route('contact.store') }}">
{{ csrf_field() }}
<div class="form-group">
<label>Full Name : </label>
<input type="text" class="form-control" name="name">
@if ($errors->has('name'))
<small class="form-text invalid-feedback">{{ $errors->first('name') }}</small>
@endif
</div>

<div class="form-group">
<label>Email : </label>
<input type="text" class="form-control" name="email">
@if ($errors->has('email'))
<small class="form-text invalid-feedback">{{ $errors->first('email') }}</small>
@endif
</div>

<div class="form-group">
<label>Address : </label>
<textarea name="address" class ="form-control"></textarea>
@if ($errors->has('address'))
<small class="form-text invalid-feedback">{{ $errors->first('address') }}</small>
@endif
</div>

<div class="form-group">
<label>Message : </label>
<textarea name="message" class ="form-control"></textarea>
@if ($errors->has('message'))
<small class="form-text invalid-feedback">{{ $errors->first('message') }}</small>
@endif
</div>

<button class="btn btn-primary">Submit</button>


</form>
</div>

</body>
</html>

这是我的 contact-message.blade.php
{{ $message }}

我也试过
{{dd($message)}}

但它没有用。

请帮忙。

最佳答案

只需从 message 更改数组键至 messages在您的 Controller 中,如下所示:

$data = array(
'messages' => $request->message
);

并在 Blade 中将其打印为 {{$messages}}

A $message variable is always passed to e-mail views, and allows the inline embedding of attachments. So, it is best to avoid passing a message variable in your view payload.



检查此链接中的注释: http://laravel.com/docs/5.0/mail#basic-usage

关于php - Laravel htmlspecialchars() 期望参数 1 是字符串,我的项目中给出的对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54645343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com