如何在laravel中连接刀片和帮手?

i want to connect a blade with an helper because i want to get "name" of HTML form field and use this "name=amount" in helper . i tried to use request to get amount in helper but did not work. is there any way to call name amount from HTML form to helper

i tried :

$request->amount

here is helper function code:

how i can see where is definattion of $deposit_amount

function updateDepositBV($id, $deposit_amount)
{
    while($id !="" || $id != "0") {
        if(isMemberExists($id))
        {
            $posid = getParentId($id);
            if($posid == "0")
                break;
            $position = getPositionParent($id);
            $currentBV = MemberExtra::where('user_id', $posid)->first();

            if($position == "L"){
                $new_lbv = $currentBV->left_bv + $deposit_amount ;
                $new_rbv = $currentBV->right_bv;
request()->input('amount') 

worked perfectly

You can call helper function from blade like

{{App\updateDepositBV(2,2340)}}

where 2 as your $id and 2340 as your $deposit_amount

If you want to access submitted form data inside a controller method you would use the Request class to get this.

There are a few different ways you can access the request object:

Dependency Injection

To do this you add an argument to method with Request as the type hint:

function updateDepositBV(Request $request ,$id, $deposit_amount)

You will also need to import the request at the top of the class:

use Illuminate\Http\Request;

Laravel will then automatically resolve this for you.


Helper Function

Instead of using dependency injection you can also just use the request() helper function to resolve the request.

Then to access the information from the form you can use the input() method on the request e.g.

$request->input('amount');

or

request()->input('amount'); //or just request('amount')

Or in most circumstances you will be able to just access the name as a property on the request ($request->amount), however, this may not always work as you may have a collision between one of your form input names and an actual property on the request class.

For more information please look at the documentation

request()->get('amount'); will work as well