如何使用有效的超链接将json文件转换为错误消息

时间:2019-07-01 08:50:49

标签: php json laravel hyperlink

我创建了一个弹出错误消息,它将接收json响应消息。但是,我已将错误翻译为返回自定义消息,其中包括希望将其转换为可单击并重定向用户的超链接的电子邮件。到目前为止,该消息可以作为json字符串打印出来,从这里我不确定如何将该字符串制成超链接。

我已将这一行代码放在validation.php

'attributes' => [
 'smtp.error' => 'Oops! Something went wrong with our mail. Drop us an email at <a href="mailto:'.config('settings.support_email').'">'.config('settings.support_email').'</a> instead.'

那是为了从我的en.json文件中转换我的字符串

"smtp.error" : "Oops! Something went wrong with our mail. Drop us an email at enquiry@helpme.com instead."

其中smtp.error将在我的控制器中转换以下错误json响应。


catch (Exception $e) {
 /*If there is an exception, get the json message and translate to what is declared as smtp.error*/
 return $request->ajax() ? response()->json(["message" => __('smtp.error')], 500) : back()->withInput()->with('error', $e->getMessage());
}

1 个答案:

答案 0 :(得分:0)

尝试像这样validation.php

'attributes' => [
    'smtp.error' => trans('smtp.error', ['email' => config('settings.support_email')),

en.php

"smtp.error" : 'Oops! Something went wrong with our mail. Drop us an email at <a href="mailto::email">:email</a> instead.'