Undefined variable: transaction_id(View: resources/views/view_all_transaction.blade.php) - php

How can i define transaction_id or initialize transaction_id in my laravel code i am stuck .
this the code on AdminContoller.php
public function provetransaction(Request $req, $transaction_id)
{
$transaction_id = transaction::find ($req->transaction_id);
$provetransaction = \DB::table('transaction')->where('transaction_id', $transaction_id)->first();
return view('provetransaction', compact('amount_paid', 'transaction_id'));
}
public function updateprove(Request $request, $transaction_id)
{
switch($request->get('approve'))
{
case 0:
Post::postpone($transaction_id);
break;
case 1:
Post::approve($transaction_id);
break;
case 2:
Post::reject($transaction_id);
break;
case 3:
Post::postpone($transaction_id);
break;
default:
break;
}
return redirect('view_all_transaction');
}
Below is my web.php where i have defined my routes.i have updated i have removed id i have used transaction_id instead.
web.php
Route::get('/view_all_transaction', 'AdminController#view_all_transaction')->name('admin');
Route::post('/view_all_transaction/{transaction_id}', 'AdminController#provetransaction')->name('admin');
Route::post('/view_all_transaction', 'AdminController#updateprove')->name('admin');
this my view_all_transaction.blade.php where the action is being passed
so where i am wrong.
<td>Moderate</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="{{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>
<!-- <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 id="btnPrint" type="button" class="btn btn-default">Approve</button>
</div>
</div>
<!-- Modal Content: ends -->

The error is indicating that you used $id in your view code. In order to do so, you should compact a variable called "id" to your view.

Try
dd($req->all());
And make sure what key are in the request

Related

Want to call each card data in their modal PHP

I want to give extra data of my card in modal where I'm trying to access card id and their data in the modal of the same card.
but I tried the same PHP code into modal but it gave me data of every id in one modal just because I didn't specify the accurate id.
This is my card code:
<?php
$postquery="SELECT * FROM card";
$run=mysqli_query($db,$postquery);
?>
<section>
<div class="container1">
<?php
while($card=mysqli_fetch_assoc($run)){
?>
<div class="container__card">
<div class="container__card--content">
<img src="../images/<?=getcardimagesinfo($db,$card['id'])?>" style="width:100%;
height:100px !important"/>
<h3><?=$card['Name']?></h3>
<h3><?=$card['id']?></h3>
<button type="button" id="modalss" class="a modalss" data-bs-toggle="modal" data-bs-
target="#exampleModal">Start</button>
</div>
</div>
<?PHP
}
?>
</div>
This one is my modal
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-
hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-light" id="exampleModalLabel">Card full Information</h5>
<button type="button" class="btn-close" data-id data-bs-dismiss="modal" aria-
label="Close"></button>
</div>
<div class="modal-body" style="color:white;">
<?PHP
while($card=mysqli_fetch_assoc($run)){
?>
<h6>Description: <?=$card['Description']?></h6>
<h6>Hint: <?=$card['hints']?></h6>
<?php
}
?>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary">Save</button>
</div>
</div>
</div>
</div>
First of all render all of your cards:
<?php
$postquery="SELECT * FROM card";
$run=mysqli_query($db,$postquery);
$allCards = [];
while($card=mysqli_fetch_assoc($run))
{
$allCards[] = $card;
}
?>
<section>
<div class="container1">
<?php
foreach($allCards as $card){
$cardId = $card['id'];
$img = getcardimagesinfo($db,$cardId);
?>
<div class="container__card">
<div class="container__card--content">
<img src="../images/<?=$img?>" style="width:100%; height:100px !important" alt="Image of card"/>
<h3><?=$card['Name']?></h3>
<h3><?=$card['id']?></h3>
<button id="card-<?=$cardId?>" type="button" class="a modalss"
onclick="updateModalContent(this)"
data-bs-toggle="modal" data-bs-target="#exampleModal">
Start
</button>
</div>
</div>
<?php } ?>
</div>
</section>
Then embed your modal at the bottom of your page content.
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title text-light" id="exampleModalLabel">Card full Information</h5>
<button type="button" class="btn-close" data-id data-bs-dismiss="modal" aria-
label="Close"></button>
</div>
<div class="modal-body" style="color:white;">
<h6>Description: <span id="modal-card-description"></span></h6>
<h6>Hint: <span id="modal-card-hint"></span></h6>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
<button type="button" class="btn btn-secondary">Save</button>
</div>
</div>
</div>
</div>
Finally add JavaScript section at the bottom to handle updating data in the modal window:
<script>
// This contains all cards info as Json object in javascript when the page is loaded
var allCards = <?php echo json_encode($allCards);?>;
// Button click handler
function updateModalContent(clickedButton)
{
let cardId = clickedButton.id.split("-")[1];
let thisCardInfo = allCards[cardId];
document.getElementById('modal-card-description').innerHTML = thisCardInfo.description;
document.getElementById('modal-card-hints').innerHTML = thisCardInfo.hints;
// and so on ....
}
</script>

Dynamically load array of objects to view them in a modal

A PHP function loops through an array of objects and lists down their titles. I have a link that opens a modal. How can I dynamically load the modal header and body with regard to the object $r from the $results when I press details?
<?php
foreach ($results as $r) {
?>
<div class="row justify-content-center">
<div class="alert alert-success">
<strong>
<?php echo $r['_source']['title']; ?></strong> <span id="showSearchTerm"></span></br>
<a data-target="#myModal" data-toggle="modal" class="MainNavText" id="MainNavHelp" href="#myModal">Details</a>
</div>
</div>
<!-- Modal -->
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<!-- <button type="button" class="close" data-dismiss="modal">×</button> -->
<h2 class="modal-title">
<?php echo $r['_source']['title']; ?>
</h2>
</div>
<div class="modal-body">
<p>
<?php echo $r['_source']['body']; ?>
</p>
<p>
<?php echo $r['_source']['path']['real']; ?>
</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<?php
}
Take the information you need to fill up the modal from an Ajax call. After that you can add that content with:
$(".classname").append(information_from_Ajax_call_stored_in_variable);

How to update particular row in sql using the content of particular bootstrap 4 cards?

I have the following database:
| fund_name | fund_description | amount_received | actual_amount
Bootstrap With PHP :
<div class="card-deck">
<?php
$sql = "SELECT * FROM fundraiser;";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
echo '<div class="card">
<img class="card-img-top" >
<div class="card-body text-center">
<h5 class="card-title">'.$row['fund_name'].'</h5>
<div class="card-text">
<p>'.$row['fund_description'].'</p>
<h6>Amount:'.$row['actual_amount'].'</h6>
<div class="progress">
<div class="progress-bar" role="progressbar"
style="width:'.$row['amount_received'].'%;"aria-
valuenow="0" aria-valuemin="0" aria-
valuemax="1000">
</div>
</div>
<div class="mt-2">
<button type="button" class="btn btn-md btn-primary" data-
toggle="modal" data-target="#exampleModalCenter"> Donate
</button>
</div>
</div>
</div>
</div>';
}
?>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1"
role="dialog" aria-labelledby="exampleModalCenterTitle" aria-
hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLongTitle">Modal
title</h5>
<button type="button" class="close" data-dismiss="modal" aria-
label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form>
<div class="form-group">
<label for="formGroupExampleInput">Enter Amount</label>
<input type="number" class="form-control" id="formGroupExampleInput"
placeholder="Enter Amount">
</div>
<div class="form-group">
<input type="submit" class="form-control btn btn-primary btn-small"
id="formGroupExampleInput" >
</div>
</form>
</div>
</div>
</div>
</div>
</div>
Here In my above code im obtaining data from database and displaying the fundraisers using the bootstrap 4. Each fundraisers is displayed using the cards and each card has a donate button. Donate button links to a modal which has a form to pay amount to fundraisers.
My Question is how to differentiate the donate button of a particular card that payment is going on for that so that i can store 'amount_received' field in database for a particular row of fundraiser?
You can use data-id to store the id of each fundraiser. When a user click on the button to open the modal, you will get the value of data-id. In the modal form I add <input type="hidden" name="fundid" id="fundid"> to store the data-id. Try the following code:
Here is a replicate of your data in php array:
<?php
$fundraiser = array(
array('id'=>1,'fundname'=>"Anyname","description"=>"About fund","actual_amount"=>50.00,'amount_receive'=>40),
array('id'=>2,'fundname'=>"Anyname2","description"=>"About fund3","actual_amount"=>100.00,'amount_receive'=>90),
array('id'=>3,'fundname'=>"Anyname3","description"=>"About fund3","actual_amount"=>20.00,'amount_receive'=>10)
);
?>
The HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<div class="card-deck">
<?php
foreach($fundraiser as $key=>$val):
echo '<div class="card">
<img class="card-img-top" >
<div class="card-body text-center">
<h5 class="card-title">'.$val['fundname'].'</h5>
<div class="card-text">
<p>'.$val['description'].'</p>
<h6>Amount:'.$val['actual_amount'].'</h6>
<div class="progress">
<div class="progress-bar" role="progressbar"
style="width:'.$val['amount_receive'].'%;"aria-
valuenow="0" aria-valuemin="0" aria-
valuemax="1000">
</div>
</div>
<div class="mt-2">
<button type="button" class="btn btn-md btn-primary fundid" data-toggle="modal" data-target="#exampleModalCenter" data-id="'.$val['id'].'"> Donate
</button>
</div>
</div>
</div>
</div>';
endforeach; ?>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Modal Header</h4>
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<form method="POST" action='updatedb.php'>
<div class="modal-body">
<div class="form-group">
<label for="formGroupExampleInput">Enter Amount</label>
<input type="number" name="amount" class="form-control" id="formGroupExampleInput" placeholder="Enter Amount">
</div>
<input type="hidden" name="fundid" id="fundid">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<button type="submit" class="form-control btn btn-primary btn-small" id="formGroupExampleInput">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
</html>
To get data-id and store in the form
<script type="text/javascript">
$('.fundid').on('click', function (e) {
$('#fundid').val($(this).attr("data-id"));
});
We don't want to leave trace of the data-id when we close the modal dialog
$('#exampleModalCenter').on('hidden.bs.modal', function () {
$('#fundid').val('');
});
</script>
When you submit the form, it will submit the data to updatedb.php. In updatedb.php, to get the form data:
the content of updatedb.php
<?php
$fundid = $_POST['fundid'];
$amount = $_POST['amount'];
echo "ID=>".$fundid."<br> Amount=>".$amount;
?>

Open Modal from another page Laravel

I working on laravel project and I have many modals that I will using in my project so I decided to put modals code in another folder .
my view code is
<button type="button" class="btn btn-success" data-toggle="modal" data-
target="#AddUserMoodal"><i class="fa fa-edit" aria-hidden="true"></i>
when I pressing on this button I want to open AddModal which is in modals folder
this is code of /modals/addmodal.blade.php
<div id="addModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title"></h4>
</div>
<div class="modal-body">
<form class="form-horizontal" role="form">
<div class="form-group">
<label class="control-label col-sm-2" for="title">Title:</label>
<div class="col-sm-10">
<input type="text" class="form-control" id="title_add" autofocus>
<small>Min: 2, Max: 32, only text</small>
<p class="errorTitle text-center alert alert-danger hidden"></p>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="content">Content:</label>
<div class="col-sm-10">
<textarea class="form-control" id="content_add" cols="40" rows="5"></textarea>
<small>Min: 2, Max: 128, only text</small>
<p class="errorContent text-center alert alert-danger hidden"></p>
</div>
</div>
</form>
<div class="modal-footer">
<button type="button" class="btn btn-success add" data-dismiss="modal">
<span id="" class='glyphicon glyphicon-check'></span> Add
</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">
<span class='glyphicon glyphicon-remove'></span> Close
</button>
</div>
</div>
</div>
</div>
</div>
but I don't know how to do that .what is the route will be for it
suppose you are in home page : home.blade.php , use include
<body>
#include('models/addmodal')
</body>
If your modal is dynamic , and you want to pass data to modal :
<body>
#include('models/addmodal',['title'=>$title,'data'=>$data])
</body>
and in your addmodal
<div id="addModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
{{$title}}
</div>
</div>
</div>
</div>
Take a look at the #include directive.
Side note:
Just for reference, back in the old of Laravel you could solve it like this:
// routes.php (which is web.php now)
Route::get('view-component/{name}', function ($name) {
return view($name);
});
// In your view
{{ route('view-component/user-form') }}
You just need to include your blade file with
#include('path.to.your.blade')
You can have your HTML structure in parts and just include them as above.
Check Laravel documentation for blade: https://laravel.com/docs/5.6/blade#including-sub-views

pass multiple php variables to modal

i want to pass multiple php variables to my modal. this how I am passing my variables but i also want to pass $idd and $gift variable to the modal
$gift ="plasma";
$idd = 4;
$track = "ty67890iuoj":
<li><a data-toggle="modal" data-target="#mySing<?php echo $track; ?>">View</a></li>
//modal
<div id="mySing<?php echo $track; ?>" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="text-center">Order Details</h4>
</div>
<div class="modal-body">
<h3 class="text-center">Print Details</h3>
<div class="text-center">
<?php $notan = DataDB::getInstance()->select_from_where('order_printd','trackingnumber',$track);
foreach($notan as $ron):?>
<span style="padding-right: 5px;font-weight: 600;"><?php echo DataDB::getInstance()->get_name_from_id('name','print_type','print_type_id',$ron['print_type_id']);?></span>
<?php endforeach; ?>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>

Categories