Laravel在表单提交后显示空值 [英] Laravel showing null value after form submit

查看:55
本文介绍了Laravel在表单提交后显示空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图:

<form action="/AddJuiceForm" method="POST">
    @csrf;
    <div class="form-group">
        <label for="FruitName">Fruit Name : </label>
        <input type="text"
            class="form-control"
            placeholder="Enter the Fruit Name"
            name="fruitname">
    </div>
    <div class="form-group">
        <label for="JuiceName">Juice Name : </label>
        <input type="text"
            class="form-control"
            placeholder="Enter the Juice Name"
            name="juicename">
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
</form>

我的路线/web.php:

Route::post('AddJuiceForm','JuiceController@insertjuice ');

我的控制器:

<?php

namespace App\Http\Controllers;

use App\JuiceModel;
use Illuminate\Http\Request;

class JuiceController extends Controller
{
    public function insertjuice()
    {
        dd(request()->all);
    }
}

结果:我的输出为空"

Result: I am getting 'null' as output

请帮助我哪里出问题了吗?

Help me where I am going wrong?

推荐答案

Illuminate \ Http \ Request 对象注入到 insertjuice 方法中,然后调用在您的 JuiceController 类中的变量上的all() 方法:

Inject the Illuminate\Http\Request object into the insertjuice method and then call the all() method on the variable within your JuiceController class:

public function insertjuice(Request $request)
{
    dd($request->all());
}

这篇关于Laravel在表单提交后显示空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆