简体   繁体   中英

Laravel showing null value after form submit

My View:

<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>

My Routes/web.php:

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

My Controller:

<?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?

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());
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM