我在URI/posts?type=press
上有一个查询参数
我正在获取index()
方法并将其传递给视图,一切都按预期工作。
// Controller
public function index(Request $request)
{
$type = $request->get('type');
return Inertia::render('Post', [
'type' => $type
]);
}
// Vue
<div class="types" v-if="$page.props.type === 'press'">
</div>
然而,当我对store()
方法做同样的事情时,它甚至不识别$type
它识别$request->input('inputText')
但不识别$type
public function store(Request $request)
{
$type = $request->get('type');
if ($type === 'press') {
return 'type press on submit';
}
if(empty($request->input('inputText'))) {
return 'field must not be empty';
}
}
我放弃了这种方法,而是将Vue/Inertia的URI参数作为有效负载的一部分传递给控制器。
data() {
return {
form: {
length: null,
inputText: null,
type: window.location.search.substring(6),
}
}
}
在控制器
$type = $request->type;
if ($type === 'press') {
return 'type press on submit';
}