php - 如何在重定向 URL Laravel 8 和 Inertiajs 中保留哈希
问题描述
我正在使用带有 Inertiajs 和 React 的 Laravel 8。我正在尝试重定向到在 url 末尾带有哈希的 url,并且由于某种原因,无论我如何构造 url,Laravel 都会在最后剥离片段。即使我明确使用withFragment
,它也不起作用。这是我的控制器:
/**
* Handle request to store a new answer
*/
public function store(Request $request)
{
$userId = Auth::id();
$question = Question::find($request->input('question')['id']);
$questionAuthor = User::find($question->user_id);
$answer = $request->input('answer');
$newAnswer = new Answer;
$newAnswer->body = $answer['body'];
$newAnswer->user_id = $userId;
$newAnswer->question_id = $question->id;
$newAnswer->save();
Mail::to($questionAuthor)->send(new NewAnswer(
$questionAuthor,
$newAnswer,
$question
));
$url = url("/questions/{$question->slug}");
return redirect($url)->withFragment($newAnswer->id);
}
如果有人可以帮助我理解为什么哈希会从最后被剥离以及我如何修复它,我将非常感激。谢谢。
解决方案
推荐阅读
- java - 本地主机的 InetSocketAddress
- php - PHP 获取多个数据
- php - get_headers 不同的结果 xampp localhost
- angular - 来自 FormBuilder 的角度转换。样式到 FormGroup。如何创建Formarray?
- ruby-on-rails - 如何通过 Ruby on Rails 中的 API GET 请求访问(并保存到我的数据库)JSON 数组中的嵌套对象/属性?
- jenkins - 将构建信息发布到来自 jenkins 的通用人工仓库
- scala - Scala Play 2.8 Framework:分割路由文件,前缀包含动态部分
- haskell - Haskell如何将文件分成多个文件
- javascript - 从 PDF 中提取 PDF 表单元数据
- quarkus - Quarkus Panache 在 1.8 之后无法使用 persistence.xml