how do i apply condition through the table values? - php

I am making a carousel which should display the info dynamically in it. And here i am trying to apply condition through which the result can be filtered but it doesn't seems to be working. Below is the code for it.(what i really want to achieve through this is to appear the results in a carousel). Any kind of help would be immensely appreciated
<div class="container">
<div class="row" style="padding: 75px">
#if($tours->continent_id == 5)
<div class="row">
<div class="col-md-9">
<h3>Featured {{$tours->continent->name}}</h3>
</div>
<div class="col-md-3">
<!-- Controls -->
<div class="controls pull-right hidden-xs">
<a class="left fa fa-chevron-left btn btn-success"
href="#carousel-example"
data-slide="prev"></a><a class="right fa fa-
chevron-
right btn btn-success" href="#carousel-example"
data-slide="next"></a>
</div>
</div>
</div>
<div id="carousel-example" class="carousel slide hidden-xs" data-
ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner">
<div class="item active">
<div class="row">
#foreach($tours as $tour)
<div class="col-sm-3">
<div class="col-item">
<div class="photo">
<img src="{{$tour->photo->file ?
asset($tour->photo->file): asset('images/404.png')}}"
class="img-responsive" alt="a" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>{{$tour->location}}</h5>
<h5 class="price-text-
color">
{{$tour->service}}</h5>
</div>
<div class="rating hidden-sm
col-md-
6">
<i class="price-text-color
fa
fa-star"></i><i class="price-text-color fa fa-star">
</i><i class="price-text-color
fa
fa-star"></i><i class="price-text-color fa fa-star">
</i><i class="fa fa-star"></i>
</div>
</div>
<div class="separator clear-left">
<p class="btn-add"> <i class="fa fa-shopping-cart"></i>Add to cart
</p>
<p class="btn-details"> <i class="fa fa-list"></i>More details
</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
#endif
</div>
</div>
Here is the controller part of the code. which is including all the fillable values in the form view. which later can be used to apply conditions on the form or return it's table values in the form
public function index()
{$tours = Tour::all();
return view('admin/tour/slider',compact('tours'));}
Error page error message

What you want is to filter the tours and only interact with the ones that contain continent_id equals to 5?
In that case, you should improve the query on database
$tours = Tour::where('continent_id', 5)->get();
Or filter the collection
$tours->filter(function ($tour) {
return $tour->continent_id == 5;
}
In both cases, you won't be able to do {{ $tours->continent->name }} since you're working with a Collection of Tour, not with a Tour instance.
In order to print the title of the first tour you should do
$tours->first()->continent->name

All i had to do was to put if condition after the foreach statement for its values to be available for the loop at before that foreach loop i had to check for the existence of the values in the table like #if($tours). and it all worked nicely :)

Related

How to access form element in while loop in PHP

i want to get acces to comment and get the value of it , i used $_POST but i get error
Undefined array key
the code create photo posts with while loop the post also contains the comment section.
here the Photo post code:
<!-- Photos section -->
<section>
<div class="container mt-5">
<div class="album py-5 bg-light">
<div class="row row-cols-1 row-cols-sm-1 row-cols-md-1 row-cols-lg-1">
<div class="container">
<?php
if (mysqli_num_rows($res_for_pics) > 0) {
while ($pics = mysqli_fetch_assoc($res_for_pics)) { ?>
<div class="col mb-3">
<div class="card shadow-sm">
<img src="images/user/<?= $pics['pic'] ?>" class="card-img-top img-fluid" alt="...">
<div class="card-body">
<h5 class="card-title" id="add-com"><?php echo $pics['pic_title'] ?></h5>
<p class="card-text"><?php echo $pics['pic_des'] ?></p>
<div class="d-flex justify-content-between align-items-center">
<small class="text-muted mb-3">by nithan</small>
</div>
<div class="accordion-item">
<h2 class="accordion-header" id="headingOne">
<button class="accordion-button" type="button" data-bs-toggle="collapse" data-bs-target="#collapseOne" aria-expanded="true" aria-controls="collapseOne">
<h5 class="card-title"> Comments</h5>
</button>
</h2>
<div id="collapseOne" class="accordion-collapse collapse show" aria-labelledby="headingOne" data-bs-parent="#accordionExample">
<div class="accordion-body">
<ul class="list-group list-group-flush">
<li class="list-group-item">
howa
<p class="card-text"><small class="text-muted"></small></p>
</li>
</ul>
</div>
</div>
</div>
**I Want to get access to the value of textarea in the other php file**.
<form method="$_POST" action="../model/comment.php">
<div class="mb-3 mt-5">
<h5 for="message-text" class="col-form-label">add your comment</h5>
<textarea type="text" class="form-control" id="message-text" name="theComment"></textarea>
</div>
<button type="submit" class="btn btn-primary text-light" name="addComment">Comment</button>
</form>
</div>
</div>
</div>
<?php }
} ?>
</div>
</div>
</div>
</div>
</section>
and here comment.php
<?php
include('db_con.php');
$comment = $_POST["theComment"];
echo $comment;
So i try to get access to the 'theComment' value from the form .

Show content for an specific item in Laravel

I have a list of Pipelines and their stages, I need tho show the stages of each pipelines when these are clicked. The thing is that I don't want to show them all, just the ones that are clicked...
I have this code on my project, the thing is that with this it shows all of the stages of all of the pipelines, and I need just show the stages of the clicked pipeline. How can I dynamically link each other
<div class="panel-body" id="body-pipelines">
#foreach($pipelines as $key => $pipeline)
<div class="pipelines">
<div class="col-md-3 row">
<div class="col-md-12 col-sm-12 col-xs-12 p-t-10 p-b-10" id="pipelines-sidebar">
<i class="fas fa-lg fa-fw m-r-10 fa-{{$pipeline->icon}}"></i>
<span>{{$pipeline->name}}</span>
</div>
</div>
<div class="col-md-8">
<div class="row float-right">
<button class="btn"><i class="fas fa-plus-circle" id="agregar"></i></button>
</div>
<div class="sortable box row">
#foreach ($pipeline->stages as $stage)
<div class="stages txt username m-b-10" id="stages-{{$stage->id}}" style="background: {{$stage->color}}" onclick="javascript:;" data-type="text">{{$stage->name}} <div class="delete-stage float-right"><button class="btn btn-danger"><i class="fas fa-trash" id="eliminar"></i></button></div></div>
#endforeach
</div>
</div>
</div>
#endforeach
</div>

update a section of a view

I have a problem updating a section of a laravel view. that section is in another view and is filled with the data of a db. What I want to do is that when clicking on a link that content is filtered and the other parts of the page remain as they were.
thanks
coursesCategories.blade.php
#extends('courses')
#section('content')
#extends('courses')
#section('content')
<div class="tab-pane fade show active" id="pills-todas" role="tabpanel" aria-labelledby="pills-todas-tab">
<div class="row justify-content-sm-center">
#foreach($cursos as $curso)
<div class="col col-12 col-sm-12 col-md-6 col-lg-4 vista_curso">
<div class="card column_course">
<a><img class="card-img-top img_course" src="{{ asset('assets/images/pictureDefault.png') }}" alt="Foto de curso" width="240" height="135"></a>
<div class="card-body column_course_interna">
<div class="include">
<div class="card-title titulo_curso">
<h3><b>{{ $curso->nombre }}</b></h3>
</div>
<ul>
<li>
<i class="fas fa-file col-1"></i>
<span class="lista_contenido col-11"> 4 documentos explicativos </span>
</li>
<li>
<i class="fas fa-clock col-1"></i>
<span class="lista_contenido col-11"> 32 minutos </span>
</li>
</ul>
</div>
<div class="compra">
<div><button type="button" class="btn btn-lg btn_suscribe btn_ver" style="width: 84%;">Ver Curso</button></div>
<div><button type="button" class="btn btn-lg btn_suscribe" style="width: 84%;">Suscribirse</button></div>
</div>
<div class="texto_precio">
<span class="price">20.99€</span>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
#stop#stop
courses.blade.php
<div id="mostrar_cursos" class="container-fluid justify-content-center mostrar_cursos">
<div class="btn_filtros"> <button id="btn_filtros" type="button" class="btn btn-primary btn-sm btn-block d-md-none" onclick="viewfilter();ocult()">Filtrar</button></div>
<div class="row">
<div class="d-none d-md-block col col-md-4 col-lg-3 filter" style="max-width: 304px">
<div class="nav flex-column nav-pills" id="pills-tab" role="tablist" aria-orientation="vertical">
<a class="nav-link active" id="pills-todas-tab" href="{{ action('CoursesController#showList') }}" role="tab" aria-controls="pills-todas" aria-selected="true">Todas</a>
#foreach($categorias as $categoria)
<a class="nav-link" id="pills-ofimatica-tab" href="{{ action('CoursesController#showCourses', $categoria->nombre) }}" role="tab" aria-controls="pills-".$categoria aria-selected="false">{{ $categoria->nombre }}</a>
#endforeach
</div>
<div class="rango_precio">
<form>
<label for="customRange">Rango de precio</label>
<input type="range" class="custom-range" id="customRange">
</form>
<div id="result">Valor menor que:
<b id="valor"></b>
<strong>€</strong>
</div>
</div>
<div class="order_by">
<button id="btn_ordenar" class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Ordenar por precio
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<button class="dropdown-item" type="button">Precio más alto</button>
<button class="dropdown-item" type="button">Precio más bajo</button>
</div>
</div>
</div>
<div class="col col-md-8 col-lg-9 row">
<div class="navegador_category container">
<div class="tab-content" id="pills-tabContent">
#yield('content')
</div>
</div>
</div>
</div>
</div>
coursesController
class CoursesController extends Controller
{
// list all categories and courses
public function showList() {
// categories extracted from the bd
$categorias = \App\Categoria::listaTodasLasCategorias();
// filtering courses according to html
$cursos = \App\Curso::listaTodosLosCursos();
return view('courses.coursesCategories',['cursos' => $cursos, 'categorias' => $categorias]);
}
// list all categories and courses
public function showCourses(Request $request, String $category) {
// categories extracted from the bd
$categorias = \App\Categoria::listaTodasLasCategorias();
// filtering courses according to html
$cursos = \App\Curso::listarCursosPorCategoria($category);
$view = View::make('courses.coursesCategories', ['cursos' => $cursos]);
if(Request::ajax()) {
$sections = $view->renderSections(); // returns an associative array of 'content', 'head' and 'footer'
return $sections['content']; // this will only return whats in the content section
}
return $view;
}
}
routes
Route::get('/courses', 'CoursesController#showList');
Route::get('/courses/{category}', 'CoursesController#showCourses');

Retrieve Data in dynamic tabs

here i'm trying to click on any tabs to retrieve it's own data i did it well and it really retrieves the data of one raw only ?! any help?
<div class="col-lg-12">
<div class="tabs-container">
<ul class="nav nav-tabs">
#foreach($departments as $department)
<li class=""><a data-toggle="tab" href="#tab-{{ $department->id }}" aria-expanded="false">{{ $department->name }}</a></li>
#endforeach
</ul>
<div class="tab-content">
#foreach($works as $work)
<div id="tab-{{ $work->department_id }}" class="tab-pane">
<div class="panel-body">
<div class="row employees">
<div class="col-md-3">
<div class="thumbnail">
<div class="image view view-first"> <img class="img-responsive" src="" name="imaged" alt="image"> </div>
<div class="caption">
<h4>{{ $work->address }} </h4>
<p>{{ $work->body }}</p>
</div>
</div>
<a class="btn btn-primary" href="edit-portfolio.html"> تعديل</a>
<button class="btn btn-danger demo4"> حذف
</button>
</div>
</div>
</div>
</div>
#endforeach
</div>
</div>
</div>
<!-- -->
</div>
i don't need to make it ajax if anyone have a good reason for why it give me only one record for each department?
The reason why you get one record for department is that your loop create one tab panel per work, for example if you have 2 works (1,2) belongs to one department (1) the result would be 2 tabs with the same id set to 1:
departments:
id
-----
1
works:
id department_id
---------------------
1 1
2 1
Html result:
<div id="tab-1" class="tab-pane">
...
</div>
<div id="tab-1" class="tab-pane">
...
</div>
note that both tabs have the same id tab-1.
Solution
group works by department_id, something like this:
$works = Work::all()->groupBy('department_id');
and then in your view:
<div class="tab-content">
#foreach($works as $department_id => $department_works)
<div id="tab-{{ $department_id }}" class="tab-pane">
<div class="panel-body">
<div class="row employees">
#foreach($department_works as $work)
<div class="col-md-3">
<div class="thumbnail">
<div class="image view view-first"> <img class="img-responsive" src="" name="imaged" alt="image"> </div>
<div class="caption">
<h4>{{ $work->address }} </h4>
<p>{{ $work->body }}</p>
</div>
</div>
<a class="btn btn-primary" href="edit-portfolio.html"> تعديل</a>
<button class="btn btn-danger demo4"> حذف </button>
</div>
#endforeach
</div>
</div>
</div>
#endforeach
</div>
Hope this helps

Dynamic php modal

I'm trying create modal that is dynamic and pre fills with the details of the item that is clicked on. Here is my code:
HTML:
{foreach from=$flowers3 item=row}
{foreach from=$row item=item}
<div class="item col-lg-4 col-md-4 col-sm-4 col-xs-12">
<div class="product">
<div class="image">
<div class="quickview">
<a alt="Quick View" class="btn btn-xs btn-quickview" data-target="#modal" data-toggle="modal"> View </a>
</div>
<a href="#">
<img class="item_thumb img-responsive" src="img/{$item.im}" alt="img">
</a>
</div>
<div class="description">
<h4 class="item_name">{$item.title}</h4>
<p class="item_price">
small
<input type="Radio" name="product" value="{$item.id}s" style="border:0;cursor:pointer;" />
<span style="font-weight: bold">${$item.ps|money:0}</span> | med
<input type="Radio" name="product" value="{$item.id}m" style="border:0;cursor:pointer;" />
<span style="font-weight: bold">${$item.pm|money:0}</span> | lg
<input type="Radio" name="product" value="{$item.id}l" style="border:0;cursor:pointer;" />
<span style="font-weight: bold">${$item.pl|money:0}</span>
</p>
</div>
<div class="action-control">
<a href="javascript:;" onClick="mySubmit()">
<span class="button-fill grey">
<i class="glyphicon glyphicon-shopping-cart">
</i> Add to cart </span>
</a>
</div>
</div>
</div>
{/foreach}
{/foreach}
Here's the PHP:
<?php
$GLOBALS['flowers']=getFlowers();
function &getFlowers(){
static $flowers;
if(!isset($flowers)){
$flowers=array(
'1'=>array('im'=>'store-a1.jpg','title'=>'CocoChanel','description'=>' Fashion fades.'),
'2'=>array('im'=>'store-a2.jpg','title'=>'The Royal Jewels','description'=>'Fit for any Queen.'),);}
$i=1;
foreach($flowers as $k=>&$v){
$v['id']=$k;
$v['num']=$i++;}
return $flowers;}
?>
And here's the modal:
<!--modal -->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<button aria-hidden="true" data-dismiss="modal" class="close" type="button"> ×</button>
<div class="col-lg-5 col-md-5 col-sm-5 col-xs-12">
<!-- product Image -->
<div class="main-image col-lg-12 no-padding style3 modal-image">
<a class="product-largeimg-link" href="#">
<img src="img/{$item.imb}" class="img-responsive product-largeimg" alt="img">
</a>
</div>
<!--/image-->
</div>
</div>
<!--/ product Image-->
<div class="col-lg-7 col-md-7 col-sm-7 col-xs-12 modal-details no-padding">
<div class="modal-details-inner">
<h1 class="product-title">{$item.title}</h1>
<div class="details-description">
<p>{$item.description}</p>
</div>
<div class="clear"></div>
</div>
</div>
</div>
</div>
<!--/modal -->
When I add the modal within the {foreach} tags, it only fills with the information for one particular item (depending on where I place it. ex: it might be the first item, or if I place it between the {foreach from=$flowers3 item=row} it will be the last of the first row) but I can't get it to update every item on the particular "Quick View" that is clicked.
Thanks in advance for any help!!
Store the properties of the items in data-attributes of the item 's in your html:
<div class="item ..." ... data-title="Nice flower" data-price="€1,20" > ... </div>
Now use some javascript to update the modal. jQuery example:
$('.item').click(function(){
var el = $(this);
$('.modal .product-title').text(el.attr('data-title'));
// and the rest of the properties, then open the modal
});

Categories