Create multiple modals in a loop while passing data - php

I am trying to make a display while looping through items and displaying buttons. The buttons can open modals that display some data. I have tried to pass the data to the modal but it is just displaying the first iteration of the loops information and never get's updated. What do I need to do to make a modal for each iteration of my list?
#foreach ($forms as $form)
<div class="row">
<div class="col-lg-2">
<div style="float:left; padding-right: 10px;">
<a href="/form/{{$cuid}}/{{$form['cuBaseName']}}"
data-toggle="tooltip" title="Edit Fields"
><i class="fas fa-edit fa-2x"></i></a>
</div>
<div style="float:left; padding-right: 10px;">
<span data-toggle="modal" data-target="#copyFormModal">
<a href="#" data-toggle="tooltip" title="Copy"
><i class="fas fa-copy fa-2x"></i></a>
</span>
</div>
<div style="float:left; padding-right: 10px;">
<span data-toggle="modal" data-target="#deleteFormModal">
<a href="#" data-toggle="tooltip" title="Delete">
<i class="fas fa-trash-alt fa-2x"></i></a>
</span>
</div>
</div>
</div>
<hr>
#include('layouts.partials.modals.copyFormModal',['cuid'=>$cuid, 'cuBaseName'=> $form['cuBaseName']])
#include('layouts.partials.modals.deleteFormModal',['cuid'=>$cuid, 'cuBaseName'=> $form['cuBaseName']])
#endforeach
<!-- Modal -->
<div class="modal fade" id="deleteFormModal" tabindex="-1" role="dialog" aria-labelledby="deleteFormModal" aria-hidden="true" >
<div class="modal-dialog" role="document" style="max-width:900px;">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="exampleModalLabel">Delete Form</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete form <b>{{$cuBaseName}}</b> from <b>{{$cuid}}</b>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" data-dismiss="modal"
onclick='location.href="/forms/{{$cuid}}/{{$cuBaseName}}/delete"' >Delete</button>
</div>
</div>
</div>
</div>

Try this, add a unique #id to each modal window:
#foreach ($forms as $form)
<div class="row">
<div class="col-lg-2">
<div style="float:left; padding-right: 10px;">
<a href="/form/{{$cuid}}/{{$form['cuBaseName']}}"
data-toggle="tooltip" title="Edit Fields"
><i class="fas fa-edit fa-2x"></i></a>
</div>
<div style="float:left; padding-right: 10px;">
<span data-toggle="modal" data-target="#copyFormModal-{{$cuid}}">
<a href="#" data-toggle="tooltip" title="Copy"
><i class="fas fa-copy fa-2x"></i></a>
</span>
</div>
<div style="float:left; padding-right: 10px;">
<span data-toggle="modal" data-target="#deleteFormModal-{{$cuid}}">
<a href="#" data-toggle="tooltip" title="Delete">
<i class="fas fa-trash-alt fa-2x"></i></a>
</span>
</div>
</div>
</div>
<hr>
#include('layouts.partials.modals.copyFormModal',['cuid'=>$cuid, 'cuBaseName'=> $form['cuBaseName']])
#include('layouts.partials.modals.deleteFormModal',['cuid'=>$cuid, 'cuBaseName'=> $form['cuBaseName']])
#endforeach
<!-- Modal example -->
<div class="modal fade" id="deleteFormModal-{{$cuid}}" tabindex="-1" role="dialog" aria-labelledby="deleteFormModal" aria-hidden="true" >
<div class="modal-dialog" role="document" style="max-width:900px;">
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title" id="exampleModalLabel">Delete Form</h3>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
Are you sure you want to delete form <b>{{$cuBaseName}}</b> from <b>{{$cuid}}</b>?
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-success" data-dismiss="modal"
onclick='location.href="/forms/{{$cuid}}/{{$cuBaseName}}/delete"' >Delete</button>
</div>
</div>
</div>
</div>
Hope it helps.

Related

Trying to show currently authenticated user post in laravel view

I am working on a Laravel project and I want to display currently authenticated users posts in view file, I am getting an error while trying to achieve that says
"Class name must be a valid object or a string"...
my blade view
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div id="accordion">
<div class="card">
<div class="card-header" id="headingOne">
<h5 class="mb-0">
<button class="btn btn-link" data-toggle="collapse" data-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Swap
</button>
</h5>
</div>
<div id="collapseOne" class="collapse show" aria-labelledby="headingOne" data-parent="#accordion">
<div class="card-body">
#foreach($data as $dat)
<div class="card mb-3" style="max-width: 540px;">
<div class="row g-0">
<div class="col-md-4">
<img
src="{{asset('images/' . $dat->imogi)}}"
alt="Trendy Pants and Shoes"
/>
</div>
<div class="col-md-8">
<div class="card-body">
<div style="text-align: right;">
<small style="color:#3490dc;">{{$dat->organazation}}</small> <small><i class="fa fa-calendar" style="color:#3490dc" aria-hidden="true"></i> {{ $dat->created_at->format('d/m/Y') }}</small>
</div>
<h5 class="card-title"><i class="fa fa-user-circle-o" style="color:#3490dc" aria-hidden="true"></i> {{$dat->name}}</h5>
<small><i class="fa fa-map-marker" style="color:#3490dc" aria-hidden="true"></i> {{$dat->location}}</small> | <small><i class="fa fa-phone" style="color:#3490dc" aria-hidden="true"></i>{{$dat->contact}}</small>
<hr/>
<p class="card-text">
<b>{{$dat->title}}</b>
</p>
<small style="color:#3490dc;">M{{$dat->price}}</small>
<p class="card-text">
{{$dat->message}}
</p>
</div>
</div>
</div>
</div>
<br/>
#endforeach
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingTwo">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Work
</button>
</h5>
</div>
<div id="collapseTwo" class="collapse" aria-labelledby="headingTwo" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_work')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/workview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('jobs')->count()}}</small> <small>Posts</small>
</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingThree">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseThree" aria-expanded="false" aria-controls="collapseThree">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Sell
</button>
</h5>
</div>
<div id="collapseThree" class="collapse" aria-labelledby="headingThree" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_sell')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/sellview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('announces')->count()}}</small> <small>Posts</small>
</p>
</div>
</div>
</div>
<div class="card">
<div class="card-header" id="headingFour">
<h5 class="mb-0">
<button class="btn btn-link collapsed" data-toggle="collapse" data-target="#collapseFour" aria-expanded="false" aria-controls="collapseFour">
<i class="fa fa-product-hunt" aria-hidden="true"></i> Tenders
</button>
</h5>
</div>
<div id="collapseFour" class="collapse" aria-labelledby="headingFour" data-parent="#accordion">
<div class="card-body">
<form class="form-inline" type="get" action="{{url('/search_tender')}}" role="search" method="get">
<input id="search-input" type="search" name="query" class="form-control" placeholder="Search...">
<button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i></button>
</form>
<br/>
<p style="text-align:center">
<button onclick="window.location.href='/tenderview'" type="button" class="btn btn-outline-primary">View</button><small style="color:#3490dc"> {{$count = DB::table('Kinds')->count()}} </small><small>Posts</small>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br/>
#include('footer')
#endsection
My controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\User;
use DB;
class PostController extends Controller
{
//
public function mapost()
{
$data = Auth::user()->Announce::orderBy('created_at', 'DESC')->get();
return view('users.mapost',['data'=>$data]);
}
}
My route in web.php
Route::get('users/mapost', 'PostController#mapost')->name('users.mapost');
I don`t know where I am getting this wrong, i will appreciate any help thanks in advance
Look at this line:
$data = Auth::user()->Announce::orderBy('created_at', 'DESC')->get();
Here you attempt to call the orderBy method of the Auth::user()->Announce class and of course, such class does not exist. It would make sense to do something like this:
Announce::where('user_id', $youruserid)->orderByDesc('created_at');

Bootstrap modal displays grey background

I am trying to display a modal in an accordion but whenever I click on the modal button, the screen becomes grey and the modal ends up not showing.
This is my code:
#if(isset($data))
<div class="panel-group" id="accordion">
#foreach($data as $datum)
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion" href="#{{$datum['id']}}">
{{ucfirst($datum['username'])}}</a>
</h4>
</div>
<div id="{{$datum['id']}}" class="panel-collapse collapse">
<div class="panel-body">
Current balance: {{$datum['wallet']['balance']}} <br>
<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#{{$datum['id']}}">Transfer</button>
<!-- Modal -->
<div id="{{$datum['id']}}" class="modal fade in" 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="modal-title">Transfer Funds</h4>
</div>
<div class="modal-body">
<div class="col-md-3">
<label>Amount</label>
<input type="number" name="amount" class="form-control" placeholder="Amount to be transferred">
</div>
<input type="text" name="sub_agent" value="{{$datum['username']}}">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
#endforeach
</div>
#endif
You're using the same id="{{$datum['id']}}" for multiple HTML elements on your page:
<div id="{{$datum['id']}}" class="panel-collapse collapse">
...
<div id="{{$datum['id']}}" class="modal fade in" role="dialog">
Which means that these toggles:
<a data-toggle="collapse" data-parent="#accordion" href="#{{$datum['id']}}">
<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#{{$datum['id']}}">Transfer</button>
Don't know what to target. Remember: in HTML, id attributes must be unique.
Try changing to the following:
<div id="{{$datum['id']}}_collapse" class="panel-collapse collapse">
...
<div id="{{$datum['id']}}_modal" class="modal fade in" role="dialog">
And adjust your targeting elements to:
<a data-toggle="collapse" data-parent="#accordion" href="#{{$datum['id']}}_collapse">
<button type="button" class="btn btn-info btn-sm" data-toggle="modal" data-target="#{{$datum['id']}}_modal">Transfer</button>

Symfony 3 modal

why my modal don't appears when I clik in my link?
I do like this and I don't know where is wrong?
In my table, my Edit button is a dropdown button because I have two Entity joined in this table, so when I click in the link who edited one of my entity the modal don't appears, the page becomes fade only.
edit.html.twig
<a data-toggle="modal" href="#edit{{ fruit.id }}">
Edit
</a>
<div class="modal" id="edit{{ fruit.id }}">
{{ form_start(edit_form, { 'method' : 'post', 'action': path('fruit_edit', { 'id' : fruit.id }) }) }}
<div class="modal-content">
<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">Edit</h4>
</div>
<div class="modal-body">
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
</div>
</div>
{{ form_end(edit_form) }}
</div>
index.html.twig
<td>
<div class="dropdown">
<button class="btn btn-info dropdown-toggle btn-xs" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu">
<li>{{ render(controller('AppBundle:Fruit:edit', { 'id' : fruit.id } )) }}</li>
<li>href="#">Categories</a></li>
</ul>
</div>
Controller
public function editAction(Request $request, Fruit $fruit)
{
$deleteForm = $this->createDeleteForm($fruit);
$editForm = $this->createForm('AppBundle\Form\FruitType', $fruit);
$editForm->handleRequest($request);
if ($editForm->isSubmitted() && $editForm->isValid()) {
$this->getDoctrine()->getManager()->flush();
return $this->redirectToRoute('fruit_edit', array('id' => $fruit->getId()));
}
return $this->render('fruit/edit.html.twig', array(
'fruit' => $fruit,
'edit_form' => $editForm->createView(),
'delete_form' => $deleteForm->createView(),
));
}
Help me please to show what the problem, thanks!
You can try just move your <div class="modal" ... ></div> container outside the <ul></ul> tag:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet"/>
<div class="dropdown">
<button class="btn btn-info dropdown-toggle btn-xs" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu">
<li>
<a data-toggle="modal" href="#edit5">
Edit
</a>
</li>
<li>Categories</li>
</ul>
<div class="modal" id="edit5">
<form>
<div class="modal-content">
<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">Edit</h4>
</div>
<div class="modal-body">
<input>
<input type="submit" value="Edit" />
</div>
</div>
</form>
</div>
</div>
So...
edit.html.twig
<div class="modal" id="edit{{ fruit.id }}">
{{ form_start(edit_form, { 'method' : 'post', 'action': path('fruit_edit', { 'id' : fruit.id }) }) }}
<div class="modal-content">
<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">Edit</h4>
</div>
<div class="modal-body">
{{ form_widget(edit_form) }}
<input type="submit" value="Edit" />
</div>
</div>
{{ form_end(edit_form) }}
</div>
index.html.twig
<td>
<div class="dropdown">
<button class="btn btn-info dropdown-toggle btn-xs" type="button" data-toggle="dropdown">
<span class="glyphicon glyphicon-edit" aria-hidden="true"></span>
</button>
<ul class="dropdown-menu">
<li>
<a data-toggle="modal" href="#edit{{ fruit.id }}">
Edit
</a>
</li>
<li>href="#">Categories</a></li>
</ul>
{{ render(controller('AppBundle:Fruit:edit', { 'id' : fruit.id } )) }}
</div>

Display Album Images using Bootstrap Modal per album

i created the bootstrap modal. the following images are albums cover images
<ul class="list-inline galleryItems">
#foreach($albums as $album)
<li data-toggle="modal" data-target="#myModal"><a href="#myGallery" data-slide-to=""><img src="{{ url('src/images/gallery/albums_cover',$album->photo->name) }}"><br>
Caption</a></li>
#endforeach
<!--end of thumbnails-->
and i had created the modal body and footer as follows
<div class="modal fade" id="myModal">
<br><br><br><br>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<div class="pull-left">My Gallery Title</div>
<button type="button" class="close" data-dismiss="modal" title="Close"> <span class="glyphicon glyphicon-remove"></span></button>
</div>
<div class="modal-body">
<!--begin carousel-->
<div id="myGallery" class="carousel slide" data-interval="false">
<div class="carousel-inner">
<div class="item active "> <img src="{{ url('src/images/gallery/albums_cover',$first_album->photo->name) }}" alt="item{{ $album->id }}" />
<div class="carousel-caption">
<h3></h3>
<p></p>
</div>
</div>
#foreach($albums as $album)
#foreach($album->photos as $photo)
<div class="item"> <img src="{{ url("src/images/gallery/album{$album->id}",$photo->name) }}" alt="" />
<div class="carousel-caption">
<h3></h3>
<p></p>
</div>
</div>
#endforeach
#endforeach
</div>
<!--Begin Previous and Next buttons-->
<a class="left carousel-control" href="#myGallery" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left"></span></a> <a class="right carousel-control" href="#myGallery" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right"></span></a>
<!--end carousel--></div>
<!--end modal-body--></div>
<div class="modal-footer">
<div class="pull-left">
<small>Photographs by Lorempixel.com</small>
</div>
<button class="btn-sm close" type="button" data-dismiss="modal">Close</button>
<!--end modal-footer--></div>
<!--end modal-content--></div>
<!--end modal-dialoge--></div>
<!--end myModal-->></div>
So, every time i click on any album, it shows me all the photos. i just want to display just the images that belongs to that folder
Thank you in advanced

When i click button and show Full information on model popup

when i click button and show Full information on model popup
<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal" >
<i class="glyphicon glyphicon-zoom-in"></i>
</button><!-- Modal -->
the information will be show model popup
Try this
<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModal" >
<i class="glyphicon glyphicon-zoom-in"></i>
</button><div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<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>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body">
<p>Some text in the modal.</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
Live Demo

Categories