so I have done a AJAX call in Laravel project and in a method I want to return a output.
This is the output
$output = ' <div class="col-xs-12 col-width">
<div class="single-product mb-30">
<div class="single-product-item clearfix">
<div class="single-product-img clearfix">
<a href=\"{{route(\'product_details\',' . $product->slug . ')}}\">
<img class="primary-image" src="'.env('PRODUCT_URL'). $product->image . '" style="width: 200px;height: 240px" alt="">
</a>
</div>
<div class="single-product-info clearfix">
<h3>' . $product->name . '</h3>
<div class="pro-price">
' . $new . '
</div>
</div>
</div>
<div class="new-sale">
' . $offer . '
</div>
</div>
</div>';
When i click the product I see the route:
/"%7B%7Burl('product_details',test)%7D%7D/"
What should I do to fix the quotes ?
Replace
<a href="{{route(\'product_details\','.$product->slug.')}}">
by
<a href="' . route('product_details', $product->slug) . '">
Final result:
$output = ' <div class="col-xs-12 col-width">
<div class="single-product mb-30">
<div class="single-product-item clearfix">
<div class="single-product-img clearfix">
<a href="' . route('product_details', $product->slug) . '">
<img class="primary-image" src="'.env('PRODUCT_URL'). $product->image . '" style="width: 200px;height: 240px" alt="">
</a>
</div>
<div class="single-product-info clearfix">
<h3>' . $product->name . '</h3>
<div class="pro-price">
' . $new . '
</div>
</div>
</div>
<div class="new-sale">
' . $offer . '
</div>
</div>
</div>';
Then it will be fixed.
you cannot use blade outside the blade templates, use standard php. so
'<a href=\"'.route('product_details',$product->slug).'\">'
instead of
'<a href=\"{{route(\'product_details\',' . $product->slug . ')}}\">'
Related
I have a photo file in the public folder that has been given a previous name, so I display photos by combining the values, I want to keep displaying photos that do not match the photo file names with almost the same file names and ignore the values that do not match
my controller
public function test(){
$product = DB::table('t_test')->get();
//dd($product);
return view('test',compact('product'));
}
my blade
<div class="container mt-5">
<div class="row">
#foreach ($product as $p)
<div class="col-md-4">
<img src="{{ asset('product/product_' . $p->item . '_' . $p->material . '_' . $p->type . '.jpg') }}">
<p>Product Name : {{ $p->item }}</p>
<p>Material : {{ $p->material }}</p>
<p>Type : {{ $p->type }}</p>
</div>
#endforeach
</div>
</div>
my table
item
material
type
table
wood
001
table
frame
001
table
wood
002
table
alumunium
001
table
alumunium
002
file foto on public folder
product_table_wood_001.jpg
product_table_frame_001.jpg
product_table_alumunium_001.jpg
if I look at the inspect element from row 3 and 5 code it looks like this
<div class="col-md-4">
<img src="{{ asset('product/product_table_wood_002.jpg') }}">
<p>Product Name : {{ $p->item }}</p>
<p>Material : {{ $p->material }}</p>
<p>Type : {{ $p->type }}</p>
</div>
<div class="col-md-4">
<img src="{{ asset('product/product_table_alumunium_002.jpg') }}">
<p>Product Name : {{ $p->item }}</p>
<p>Material : {{ $p->material }}</p>
<p>Type : {{ $p->type }}</p>
</div>
there is no photo in public file with this name
, when this happens I still want to display the photo row 3 = "product_table_wood_001" and row 5 = "product_table_alumunium_001" because it has the closest value
the logic is something like this but I don't know how to write the correct way so that the code can run
#if (file_exists(public_path('product/thumb/thumb_' . $product->item . '')))
#if (file_exists(public_path('product/thumb/thumb_' . $product->item . ' ' . $product->material . '')))
#if (file_exists(public_path('product/thumb/thumb_' . $product->item . ' ' . $product->material . ' ' . $product->type . '.jpg')))
<img src="{{ asset('assets/product/thumb/thumb_table_wood_001.jpg') }}">
#else {{-- showing one of the pictures of almost the same first name --}}
<img src="{{ asset('assets/product/thumb/thumb_table_wood') }}"> #endif
#else
{{-- showing one of the pictures of almost the same first name --}}
<img src="{{ asset('assets/product/thumb/thumb_table') }}">#endif #else <img src="{{ asset('assets/product/thumb/no-photo.jpg') }}"> #endif
You could do the following. In the Product model write a function to get the photo url:
public function getPhotoUrl()
{
if (file_exists(asset('product/product_' . $this->item . '_' . $this->material . '_' . $this->type . '.jpg'))) {
return asset('product/product_' . $this->item . '_' . $this->material . '_' . $this->type . '.jpg');
} else {
return asset('product/product_' . $this->item . '_' . $this->material . '_001' . '.jpg');
}
}
And in the view you simply call this function:
<div class="container mt-5">
<div class="row">
#foreach ($product as $p)
<div class="col-md-4">
<img src="{{ $p->getPhotoUrl() }}">
<p>Product Name : {{ $p->item }}</p>
<p>Material : {{ $p->material }}</p>
<p>Type : {{ $p->type }}</p>
</div>
#endforeach
</div>
</div>
I hope it helps
I am trying to display images in bootstrap carousel but am not able to loop. Only one image is shown but not sliding.Am using laravel in the back end. Please assist if you can this is the code.
This is the code:
<div class="container">
<div class="row">
<div id="imageCarousel" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
#foreach($images as $value)
<li data-target="#imageCarouselIndicator" data-slide-to="{{ $loop->index }}" class="{{ $loop->first ? 'active' : '' }}"></li>
#endforeach
</ol>
<div class="carousel-inner">
<h3>{{$product->title}}</h3>
#foreach($images as $image )
<div class="item image {{ $loop->first ? 'active' : '' }}">
<div class="carousel-item active">
<img src="/images2/{{$image->filename}}" alt="{{$image->title}}">
</div>
</div>
#endforeach
</div>
<a class="carousel-control-prev" href="#imageCarousel" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#imageCarousel" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
Try this:
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
#foreach($images as $image )
<div class="carousel-item {{ $loop->first ? 'active' : '' }}">
<img src="/images2/{{$image->filename}}"/>
</div>
#endforeach
</div>
</div>
image not retrieved as i called to be seen there is a problem calling the image it don't return anything .
<div class="content-wrap">
#forelse($newss->chunk(8) as $chunk)
#foreach($chunk as $news)
<article class="blog-entry-travel animate-box">
<div class="blog-img" style="background-image: {{url('images',$news->image)}}"></div>
<div class="desc">
<p class="meta">
<span class="date">{{str_limit($news->created_at, $limit = 10, $end = '')}}</span>
<span class="pos">By {{str_limit($news->journalists->name,$limit = 10,$end = '')}}</span>
</p>
<h2>{{str_limit($news->title,$limit = 50,$end = '')}}</h2>
<p>{{str_limit($news->subject,$limit = 200,$end = '')}}</p>
<p>Read More <i class="icon-arrow-right22"></i></p>
</div>
</article>
#endforeach
#empty
<h3>No News</h3>
#endforelse
</div>
He need to add a slash too
url('images/' . $news->image)
Here {{url('images',$news->image)}} you used a comma to concatenate the URL.
Try like this:
style="background-image: {{url('images/' . $news->image)}}"
<div class="slider-img" style="background-image: url('{{ asset('/storage/images/foods/'.$food->image) }}')"></div>
This worked for me
When I update my banner_image it should delete the ones from the database Then re insert the ones that are set.
Currently what it does is deletes the banner image but then re inserts blank banner_image
But should remove that enitre row.
Question How to make sure when I update it that will remove the images rows that are no longer selected and not re insert them
public function update($bid = NULL, $data = array()) {
$banner_update = array('banner_title' => $data['banner_title'], 'banner_status' => $data['banner_status']);
$this->db->where('bid', $bid);
$this->db->update('banner', $banner_update);
$this->db->where('bid', $bid)->delete('banner_image');
if (isset($data['banner_image'])) {
$banner_images = array();
$i = 0;
foreach ($data['banner_image'] as $image) {
$banner_images[$i] = array(
'bid' => $bid,
'banner_image' => $image['image'],
);
$i++;
}
$this->db->insert_batch('banner_image', $banner_images);
}
}
View
<?php echo form_open($action);?>
<div class="container">
<div class="card mt-3">
<div class="card-body">
<?php if (validation_errors()) {?>
<?php unset($_POST);?>
<div class="bg-error-warning">
<ul>
<?php echo validation_errors('<li>', '</li>');?>
</ul>
</div>
<?php }?>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p>Banner Title</p>
<div class="form-group">
<input type="text" name="banner_title" value="<?php echo $banner_title;?>" placeholder="Enter Banner Title" class="form-control">
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<table id="images" class="table table-striped table-bordered">
<tbody>
<tr>
<td>
<button type="button" onclick="addImage();" data-toggle="tooltip" title="Add Banner!" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button>
</td>
</tr>
<?php $image_row = 0; ?>
<?php foreach ($banner_images as $banner_image) { ?>
<tr id="image-row<?php echo $image_row; ?>">
<td>
<a href="" id="thumb-image<?php echo $image_row; ?>" data-toggle="image">
<img src="<?php echo $banner_image['thumb']; ?>" alt="" title="" data-placeholder="<?php echo $placeholder; ?>" class="img-thumbnail"/></a>
<input type="hidden" name="banner_image[<?php echo $image_row; ?>][image]" value="<?php echo $banner_image['image']; ?>" id="input-image<?php echo $image_row; ?>" />
</td>
</tr>
<?php $image_row++; ?>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p>Banner Status</p>
<div class="form-group">
<?php $options = array('0' => 'Disabled', '1' => 'Enabled'); echo form_dropdown('banner_status', $options, $banner_status, array('class' => 'form-control'));?>
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-group">
<button type="submit" class="btn btn-block btn-dark">Create Banner</button>
</div>
</div>
</div>
</div>
</div>
</div>
<?php echo form_close();?>
<script type="text/javascript">
var image_row = <?php echo $image_row; ?>;
function addImage() {
html = '<tr id="image-row' + image_row + '">';
html += '<td class="text-left">';
html += '<a href="" id="thumb-image' + image_row + '" data-toggle="image" >';
html += '<img src="<?php echo $placeholder; ?>" width="100" height="100" class="img-thumbnail" data-placeholder="<?php echo $placeholder; ?>"/>';
html += '<input type="hidden" name="banner_image[' + image_row + '][image]" value="" id="input-image' + image_row + '" />'
html += '</a>';
html += '</td>';
html += '<td class="text-left">';
html += '<button type="button" onclick="$(\'#image-row' + image_row + '\').remove();" data-toggle="tooltip" title="Remove Banner!" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button>'
html += '</td>';
html += '<script>';
html += '$(document).ready(function(){';
html += '$(\'[data-toggle="tooltip"]\').tooltip();';
html += '});';
html += '<\/script>';
$('#images tbody').append(html);
image_row++;
}
</script>
Have got it working just had to put empty in the foreach loop
public function update($bid = NULL, $data = array()) {
$banner_update = array('banner_title' => $data['banner_title'], 'banner_status' => $data['banner_status']);
// Updates the main banner table
$this->db->where('bid', $bid);
$this->db->update('banner', $banner_update);
// Removes banners so can have clean insert of new banners selected
$this->db->where('bid', $bid);
$this->db->delete('banner_image');
// Inserts new banner images & saved ones.
if ($this->input->post('banner_image')) {
foreach ($this->input->post('banner_image') as $image) {
if (!empty($image['image'])) {
$this->db->insert('banner_image', array('bid' => $bid, 'banner_image' => $image['image']));
}
}
}
}
Agent controller:
public function index() {
if (!empty($_SESSION['admin'])) {
$data = array(
'page_title' => 'Agent',
'page_name' => 'agent/index',
'result' => $this->agent_model->list_all()
);
$this->load->view('template', $data);
} else {
redirect('login');
}
}
Agent model:
public function list_all() {
$data = 'agent.id,agent.name,agent.mobile,agent.vehicle,agent.address,agent.img_url,agent.category,agent.status,agent.login_status,vehicle.id AS vehicle_id,vehicle.name AS vehicle_name';
$this->db->select($data);
$this->db->from('agent');
$this->db->join('vehicle', 'agent.vehicle=vehicle.id');
return $this->db->get()->result_array();
}
View:
<?php foreach ($result as $value): ?>
<div class="col-md-4 col-sm-4 col-xs-12 profile_details">
<div class="well profile_view">
<div class="col-sm-12">
<h4 class="brief"><i>Digital Strategist</i></h4>
<div class="left col-xs-7">
<p><i class="fa fa-user"></i> Name: <?= $value['name']; ?></p>
<ul class="list-unstyled">
<li><i class="fa fa-building"></i> Vehicle: <?= $value['vehicle_name']; ?></li>
<li><i class="fa fa-phone"></i> Mobile: <?= $value['mobile']; ?> </li><br/>
<div class="onoffswitch">
<input type="hidden" value="<?= $value["id"]; ?>"/>
<input type="checkbox" class="js-switch"
<?php if ($value['status'] == 1) {
echo "checked";
} ?>>
</div>
</ul>
</div>
<div class="right col-xs-5 text-center">
<img src="/<?= $value['img_url']; ?>" alt="" class="img-circle img-responsive" style="height: 120px; width: 120px;">
</div>
</div>
<div class="col-xs-12 bottom text-center">
<div class="col-xs-12 col-sm-6 emphasis">
<p class="ratings">
<a>4.0</a>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star"></span>
<span class="fa fa-star-o"></span>
</p>
</div>
<div class="col-xs-12 col-sm-6 emphasis btn-group">
<?php if ($value['status'] == 1): ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php else: ?>
<i class="glyphicon glyphicon-pencil"> </i> Edit
<?php endif; ?>
<a href="<?= base_url("agent/detail/{$value['id']}"); ?>" class="btn btn-primary btn-xs">
<i class="fa fa-user"> </i> View Profile </a>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
Below Screenshot:
Screenshot
MY Question: How to create pagination with letters in codeigniter.
MY Question: I create agent module and i apply pagination with letters in above Screenshot. so how to apply pagination with letters in above view.