lundi 25 décembre 2017

Undefined variable of view in laravel 5.4

I define a variable in view. But problem is that it shows undefined. My task is, first i take all the input from user using form helper then i want to post it to the store function & do some calculation and then pass it to the view for showing purpose. But i tried it, unfortunately shows undefined.Undefined variable is "totalamount" Here i attached all the code:

controller:

    <?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\TestSetup;
use Illuminate\Support\Facades\Input;
class TestRequestController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $allTestNames=TestSetup::all()->pluck('test_name','id');
//        $testNames=TestSetup::orderBy('test_name')
//                      ->get();

     return view('testrequestentries.createTestRequestEntry')->withAlltestnames($allTestNames);


//        return view('testrequestentries.createTestRequestEntry');
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

//      if(Input::get('Add')) {
          $total=$request->fee+$total;
          return view('testrequestentries.createTestRequestEntry')->withTotalamount($total); 

//      }else if(Input::get('Save')){
//          
//      }
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

view

@extends ('main')
@section('title','|Test Request Entry')

@section('stylesheets')
    {!! Html:: style('css/parsley.css')!!}
@endsection  
@section('content')


            {!! Form::open(['route' => 'testrequests.store','data-parsley-validate'=>'']) !!}
                
                

                
                

                
                

                               
                         

                
                

                


                <table class="table table-bordered" style="margin-top: 50px;">
                        <thead>
                            <tr>
                              <th>SL</th>
                              <th>Test Name</th>
                              <th>Fee</th>
                              <th>Type Name</th>
                            </tr>
                      </thead>
                      @php ($i=1)   

                             <tbody>
                              <tr>
                                <th scope="row"></th>
                                <td></td>


                              </tr>
                            </tbody>  
                            @php ($i++)


                    </table>

{!! Form::close() !!}

    @section('scripts')
        {!! Html:: script('js/parsley.min.js')  !!}
    @endsection
@endsection



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire