Click here to Skip to main content
14,421,405 members
Rate this:
Please Sign up or sign in to vote.
See more:
how can i define transaction_id in my laravel code. below is my view_all_transaction.blade.php i am stuck can someone help me to fix it.thank you.
Undefined variable: transaction_id (View:resources/views/view_all_transaction.blade.php)

<td><a href="{{action('AdminController@provetransaction', $view_all_transaction->transaction_id)}}" data-toggle="modal" data-target="#MyModal" class="btn btn-warning">Moderate</a></td> 
                                                    <!-- <td><button class="btn btn-success btn-sm" data-toggle="modal" data-target="#MyModal"> Approve</button></td> -->
                                      

        <div id="MyModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
  
  <div class="modal-dialog modal-lg">
    
    <!-- Modal Content: begins -->
    <div class="modal-content">
      
      <!-- Modal Header -->
      <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
          <h4 class="modal-title" id="gridSystemModalLabel">Your Headings</h4>
      </div>

      <!-- Modal Body -->  
      <div class="modal-body">
        <div class="body-message">
          <h4>Approve </h4>
              <div class="container">
      <form method="post" action="{{action('AdminController@updateprove', $transaction_id)}}">
        @csrf
         <div class="row">
          <div class="col-md-4"></div>
            <div class="form-group col-md-4">
                <lable>Approval</lable>
                <select name="approve">
                  <option value="0" @if($view_all_transaction->status==0)selected @endif>Pending</option>
                  <option value="1" @if($view_all_transaction->status==1)selected @endif>Approve</option>
                  <option value="2" @if($view_all_transaction->status==2)selected @endif>Reject</option>
                  <option value="3" @if($view_all_transaction->status==3)selected @endif>Postponed</option> 
                </select>
            </div>
        </div>
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
      <button type="submit" class="btn btn-default">Approve</button>
<!--         <div class="row">
            <div class="col-md-4"></div>
                <div class="form-group col-md-4">
                    <button type="submit" class="btn btn-success" style="margin-top:40px">Update</button>
                </div>
        </div> -->
      </form>
    </div>
        </div>
      </div>
    
      <!-- Modal Footer -->
      <div class="modal-footer">
<!--        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
       <button type="submit" class="btn btn-success" style="margin-top:40px">Update</button> -->
<!--       <button id="btnPrint" type="button" class="btn btn-default">Approve</button>
 -->      </div>
    
    </div>
    <!-- Modal Content: ends -->


What I have tried:

my adminController.php
public function provetransaction($transaction_id)
  {

      // $transaction_id = transaction::find ($req->transaction_id);
      $provetransaction = \DB::table('transaction')->where('transaction_id', $transaction_id)->first();
      // return view('provetransaction');
      // dd($request->all());
      return view('provetransaction', compact('transaction', 'transaction_id'));
  }
  public function updateprove(Request $request, $transaction_id)
  {
      switch($request->get('approve'))
      {
          case 0:
              transaction::postpone($transaction_id);
              break;
          case 1:
              transaction::approve($transaction_id);
              break;
          case 2:
              transaction::reject($transaction_id);
              break;
          case 3:
              transaction::postpone($transaction_id);
              break;
          default:
              break;

      }
      return redirect('view_all_transaction');
  }


my routes web.php
Route::get('/view_all_transaction', 'AdminController@view_all_transaction')->name('admin');
Route::get('/view_all_transaction/provetransaction/{transaction_id}', 'AdminController@provetransaction')->name('admin');
Route::post('/view_all_transaction/{transaction_id}', 'AdminController@updateprove')->name('admin');
Posted
Updated 13-May-19 4:34am
v3

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

As best as I can tell from the code you supplied, you use $transaction_id as function argument but do not declare before such use.

Although you can just declare a symbol anywhere, you cannot use the symbol unless it is already declared.

$some_symbol = 0
function($some_symbol); // now OK

in your second code block you have:
// $transaction_id = transaction::find ($req->transaction_id);


but, you'll observe, your declaration of $transaction_id is commented out.
   
Comments
harristars 13-May-19 23:30pm
   
Undefined variable: transaction_id (0)
when i uncomment my declaration it is giving me the above error
// $transaction_id = transaction::find ($req->transaction_id);
W Balboos 14-May-19 7:49am
   
Whatever your reason, the rules for php won't change for you. You need to define a variable before you use it in such context's as an array index or function argument.

Supposed it let you do what you wanted - from where would it get a value?

You need to get a value into $transaction_id before you use it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100