What are the possible reasons why modal doesn't shows? - laravel

I have two button for modal and created two modal included in my blade file which I'm trying to use but it doesn't seem to work, I tried deleting the other button but doesn't seem to work, which I assumed to be the case
What could have been the reason for the modals not to show up?
this is my button modals
<td class="table-danger"><button id="aaaBtn" class="soldbtn btn-warning" data-toggle="modal" data-target="#soldModal{{$data->id}}">SOLD</button></td>
<td class="table-warning"><button id="bbbBtn" class="updatebtn btn-success" data-toggle="modal" data-target="#updateModal{{$data->id}}" >UPDATE</button></td>
<!-- Modal -->
<div class="modal fade" id="updateModal{{$data->id}}" tabindex="-1" role="dialog" aria-labelledby="updateModalLabel{{$data->id}}" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<img src="assets/images/rice.png">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="col-lg-12">
<div class="contact-form">
<form id="contact" action="{{url('/reservation')}}" method="post" enctype="multipart/form-data">
#csrf
<div class="row">
<div class="col-lg-12 col-sm-12" align="center">
<h3>{{$data->title}}</h3>
<img height="200" width="200" src="productimage/{{$data->image}}">
<h5 class='m-2'>~ KILOS ~</h5>
</div>
</div>
<div class="row col-12">
#foreach($modal_data as $modal_data)
<div class="row sm-6 ml-4 mb-1" class="no-gutters" style="height:25px; width: auto;">
<p class='text-dark mr-2'><input type="checkbox" name="prod_kilos[]" value="{{$modal_data->kg}}" id="checkitem" class="check-cls"/> {{$modal_data->kg}}kg </p>
<p class='text-dark'>Qty:</p><input style="width:80px; height:25px;" type="number" name="prod_qty[{{$modal_data->kg}}]" min="1" value="1" max="{{$modal_data->warehouse_qty}}" class="form-control ml-2">
<input type="hidden" name="product_name[{{$modal_data->kg}}]" value="{{$modal_data->title}}">
<input type="hidden" name="product_fee[{{$modal_data->kg}}]" value="{{$modal_data->price}}">
<input type="hidden" name="prod_id[{{$modal_data->kg}}]" value="{{$modal_data->id}}">
</div>
#endforeach
</div>
<div class=" col-lg-12 mt-5">
<button name="submit" type="submit" id="form-submit" class="submit-btn" >ADD TO CART</button>
</div>
</form>
</div>
</div>
<script>
</div>
</div>
</div>
<!-- End Modal -->

What is the problem?
I think the reason why it is not working is because you set wrong data-target to the button:
<button data-target="#updateModal">UPDATE</button>
But when creating modal you use:
<!-- Modal -->
<div id="updateModalModal{{$data->id}}">
</div>
<!-- End Modal -->
Your data-target attributes does not correspond with each other.
How to solve?
The data-target attribute should point to an existing element in page, changing it to:
<button data-target="#updateModal{{$data->id}}">UPDATE</button>
<!-- Modal -->
<div id="updateModal{{$data->id}}">
</div>
<!-- End Modal -->
should solve the problem.
Hope it helps. Read more about it here.

Related

Laravel post from modal tries to GET instead of POSt

The modal gets data from the #foreach and displays them. And from the form it posts the data entered to the next POST route {{ route('user.give') }}. However, it keeps trying to perform a GET request to a different route(precisely the route just above it). Please help, thank you for helping
#section('content')
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
#if(count($orgs) > 0)
#foreach($orgs as $org)
<div class="card m-1 col-md-3 p-0">
<img class="card-img-top" src="{{ asset('storage/'.$org->logo) }}" alt="{{ $org->name }} logo" />
<div class="card-body">
<span class="card-title"><strong><i class="fa fa-church"></i> {{ $org->name }}</strong></span>
<div class="small"><i class="fa fa-exchange-alt"></i> {{ $org->alias }}</div>
<p class="card-text"></p>
<button class="btn btn-outline-primary rounded-0" data-toggle="modal" data-target="#exampleModalCenter">
<i class="fa fa-credit-card"></i>
Give
</button>
<i class="fa fa-cogs"></i>
</div>
</div>
#endforeach
#else
<p>Sorry, there's no match for your search.</p>
#endif
and right below is the modal. It is actually continuation of the code above. The modal actually comes up, the issue only occurs at the point of posting
<!-- form 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="exampleModalCenterTitle">Details</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<cite>You are about to give to {{ $org->name }}</cite>
<!-- form -->
<form method="POST" action="{{ route('user.give') }}">
#csrf
<input type="hidden" name="organisation_name" value="{{ $org->name }}">
<input type="hidden" name="organisation_id" value="{{ $org->id }}">
<input type="hidden" name="organisation_email" value="{{ $org->email }}">
<input type="hidden" name="organisation_logo" value="{{ $org->logo }}">
<div class="form-group">
<label for="amount">Amount</label>
<input type="number" class="form-control rounded-0" name="amount" aria-describedby="amount" placeholder="e.g 5000" required>
</div>
<div class="form-group">
<label for="purpose">Purpose</label>
<input type="text" class="form-control rounded-0" name="purpose" placeholder="e.g tithe">
</div>
<button type="submit" class="btn btn-outline border-dark text-dark rounded-0" id="proceed">
Proceed
</button>
</form>
<!-- //form -->
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline border-dark text-dark rounded-0" data-dismiss="modal">Close</button>
<!-- <button type="button" class="btn btn-primary">Save changes</button> -->
</div>
</div>
</div>
</div>
<!-- //form modal -->
#endsection
Here are my routes
Route::middleware('auth')->group(function (){
Route::post('/user/search', 'HomeController#search')->name('user.search');
Route::post('/user/give/', 'HomeController#give')->name('user.give');
Route::get('/user/verify/{reference}', 'HomeController#verify')->name('user.verify');
It visits user.search instead of user.give and it does that with a GET
$org is not what you want in your modal: it is the last $org from your loop over your $orgs array since it is not inside the #foreach loop.
You need to generate your modal dynamically (through javaScript or other) when you click the button showing the modal.
Found it. Apparently I added a validation rule that was failing when the form was submitted. Since the validation error could not be sent to the modal it was performing a GET.
Breathing fresh air now. Thanks for your support y’all

how to show different bootstrap modals on a single page

I am trying to open multiple modals on a single page but their ids are conflicting with each other. I got this code from bootstrap-4 documentation,
Modal 1 is works fine but modal 2 fails to work, I wants that both of them to work separately
code:
modal1
<button type="button" class="btn btn-success" data-toggle="modal" data-target="#exampleModal">
Add New
</button>
<!-- Modal Add Owner -->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Add Owner</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="{{ route('owner.store') }}">
#csrf
<div class="form-group">
<label for="">Add Owner Name</label>
<input type="text" name="owner_name" class="form-control" id="" placeholder="Owner Name">
</div>
<input type="submit" name="submit" class="btn btn-primary" value="submit">
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
modal2:
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal">
Show
</button>
<!-- Modal Show Owner-->
<div class="modal fade" id="exampleModalshow" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabe2" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">View Owner</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form method="POST" action="{{ route('owner.update', $owner->id) }}">
#csrf
#method('PATCH')
<div class="form-group">
<label for="">Owner Name</label>
<input type="text" name="owner_name" class="form-control" value="{{ $owner->owner_name }}">
</div>
<input type="submit" name="submit" class="btn btn-primary" value="submit">
</form>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
Change data-target on the second modal button to match the modal id
<button data-target="#exampleModalshow">
... rest of the code
</button>

Bootstrap Modal is just showing last item's Data of collection rather than specific ID's data

I'am new to laravel. I've a sort of Restaurant Management System's dashboard.
I am showing menu on a blade. By selecting Category from dropdown its showing list of Dishes. Each Dish Which contains Dish Ingredients and Dish AddOn as well. Now I've Edit Button on each dish's Ingredient which will show the Modal against specific Dish's Ingredient. The problem is when I click the edit button, Modal Popup and it shows the Last Dish's Ingredients rather than the Dish's Ingredient which is intended to Edit.
#foreach($items as $item)
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div class="menu-block">
<div class="menu-content">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="dish-img"><img height="120px" width="120px" src="{{asset($item['image'])}}" alt="" class="img-circle"></div>
</div>
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
<div class="dish-content">
<h5 class="dish-title">
<b>{{$item['name']}}</b>
<i class="ft-edit"></i>
<i class="ft-trash-2"></i>
</h5>
<h6><b>Ingredients:</b></h6>
#foreach($add_ingredients as $add_ingredient)
#foreach($dish_ing as $dish_in)
#if($item['id']==$dish_in->dish_id&&$dish_in->ingredient_id==$add_ingredient['id'])
<span class="dish-meta" >/{{$add_ingredient['name']}}</span>
#endif
#endforeach
#endforeach
<i class="ft-edit"></i>Edit
<button type="button" class="btn" data-toggle="modal" data-target="#ingredient"><i class="ft-plus-square" ></i>Add</button>
<h6><b>Addons:</b></h6>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<span class="dish-meta" >/{{$add_item['name']}} </span>
#endif
#endforeach
<i class="ft-edit"></i>Edit
Modal Section:
<div class="modal fade editaddon{{$item['id']}}" id="">
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form class="form form-horizontal" method="get" action="">
#csrf
<div class="form-body">
<h4 class="form-section"><i class="ft-user"></i>Dish Addon form</h4>
<div class="form-group row">
<label class="col-md-3 label-control" for="projectinput6">Category Name</label>
<div class="col-md-9">
<select id="projectinput6" name="id2" class="form-control">
<option value="none" selected="" disabled="">Select Relevant Category</option>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<option value="{{$add_item['id']}}">{{$add_item['name']}}</option>
#endif
#endforeach
</select>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
All I want is to Show the Specific Dish's Ingredient in the Modal When Editing.
Any help will highly appreciated
I have modified the snippet and added the modal box in the main foreach loop. Also i have removed the dot from the data target.
#foreach($items as $item)
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12">
<div class="menu-block">
<div class="menu-content">
<div class="row">
<div class="col-lg-3 col-md-3 col-sm-3 col-xs-12">
<div class="dish-img"><img height="120px" width="120px" src="{{asset($item['image'])}}" alt="" class="img-circle"></div>
</div>
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12">
<div class="dish-content">
<h5 class="dish-title">
<b>{{$item['name']}}</b>
<i class="ft-edit"></i>
<i class="ft-trash-2"></i>
</h5>
<h6><b>Ingredients:</b></h6>
#foreach($add_ingredients as $add_ingredient)
#foreach($dish_ing as $dish_in)
#if($item['id']==$dish_in->dish_id&&$dish_in->ingredient_id==$add_ingredient['id'])
<span class="dish-meta">/{{$add_ingredient['name']}}</span>
#endif
#endforeach
#endforeach
<i class="ft-edit"></i>Edit
<button type="button" class="btn" data-toggle="modal" data-target="#ingredient"><i class="ft-plus-square"></i>Add</button>
<h6><b>Addons:</b></h6>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<span class="dish-meta">/{{$add_item['name']}} </span>
#endif
#endforeach
<i class="ft-edit"></i>Edit
<div class="modal fade editaddon-{{$item['id']}}" >
<div class="modal-dialog">
<div class="modal-content">
<!-- Modal Header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<!-- Modal body -->
<div class="modal-body">
<form class="form form-horizontal" method="get" action="">
#csrf
<div class="form-body">
<h4 class="form-section"><i class="ft-user"></i>Dish Addon form</h4>
<div class="form-group row">
<label class="col-md-3 label-control" for="projectinput6">Category Name</label>
<div class="col-md-9">
<select id="projectinput6" name="id2" class="form-control">
<option value="none" selected="" disabled="">Select Relevant Category</option>
#foreach($add_items as $add_item)
#if($add_item['dish_id']==$item['id'])
<option value="{{$add_item['id']}}">{{$add_item['name']}}</option>
#endif
#endforeach
</select>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endforach

How to retrieve the id from iteration to the bootstrap modal?

I need to capture the id from the iteration, but it seems to capture the last id which it's seems to be obviously,
Am using bootstrap modal which i even don't know how they code their jQuerys'.
Thus how can i do to make this button not capturing the last id?
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#applications_{{$user->id}}" id="#applications_{{$user->id}}">View applications</button>
<!-- Modal -->
<div class="modal fade" id="applications_{{$user->id}}" role="dialog" >
<div class="modal-dialog" >
<!-- Modal content-->
<div class="modal-content" style="width: 600px !important;">
<div class="modal-header">
{{-- <button type="button" class="close" data-dismiss="modal">×</button> --}}
<h4 class="modal-title">Applications</h4>
</div>
<div class="modal-body">
<div class="text-muted" style="float: left;padding-right: 10px">
<table class="table table-hover">
<tr>
<th>Company name</th>
<th>Location</th>
<th>Program</th>
<th>Application</th>
<th>Actions</th>
</tr>
#foreach($user->post as $form)
<tr>
<td>{{$form->pivot->company_name}}</td>
<td></td>
<td>{{$form->pivot->id}}</td>
<td>
/* this button is only capturing the last id from iteration */
<button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#application_{{$form->pivot->id}}" >View {{$form->pivot->file}}</button> </td>
<td></td>
</tr>
#endforeach
{{$user->name}}
</table>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="application_{{$form->pivot->id}}" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Application</h4>
</div>
<div class="modal-body">
<div class="text-muted" style="float: left;padding-right: 10px">
<div class="center image">
<img src="/storage/file/{{$form->pivot->file}}" class="img-round" alt="User Image">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Expected to retrieve an image from it's respectively post, but it only works with the last id, no errors.
Your second modal is outside the foreach, then id="application_{{$form->pivot->id}}" only works with the last value it took in the loop. To do it with a blade, you can redo the loop and create a modal for each id and image:
<!-- 2nd Modal -->
#foreach($user->post as $form)
<div class="modal fade" id="application_{{$form->pivot->id}}" role="dialog">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h4 class="modal-title">Application</h4>
</div>
<div class="modal-body">
<div class="text-muted" style="float: left;padding-right: 10px">
<div class="center image">
<img src="/storage/file/{{$form->pivot->file}}" class="img-round" alt="User Image">
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
#endforeach

bootstrap modal onclick closing

I have form to submit signon inside a modal. It is not allowing me to enter email and password. When I click on the form element it is closing.What am I doing wrong here.It is supposed to enter the email and password to submit
Form Modal
<div id="click_signin" class="modal New-Bouncing-popup" role="dialog">
<div class="modal-dialog bounce animated modal-ku">
<!-- Modal content-->
<div class="modal-content1">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
</div>
<div class="modal-body row">
<div class="col-sm-6 left-side">
<h1>Surplus<br>Forex.</h1>
<p>Build your profitable forex career.</p>
<br>
<p>Login with social media</p>
<a class="fb" href="#" target="_blank">Login With Facebook</a>
<a class="tw" href="#" target="_blank">Login With Twitter</a>
</div><!--col-sm-6-->
<div class="col-sm-6 right-side">
<h1>Login</h1>
<p>Fill the below given fields to Login</p>
<br/>
<!--Form with header-->
<div class="form">
<div class="form-group">
<label for="form2">Your email</label>
<input type="text" id="form2" class="form-control">
</div>
<div class="form-group">
<label for="form4">Your password</label>
<input type="password" id="form4" class="form-control">
</div>
<div class="text-xs-center frm_grp">
Login
</div>
</div>
<!--/Form with header-->
</div><!--col-sm-6-->
</div>
</div>
</div>
</div>

Resources