how to display or call value in array in laravel blade view ?
I already have the data that appears in the image below:
enter image description here
I still don't understand how to call the data in the :
<h3>#currency($laporan->Total_Sayur)</h3>
I'm tired of trying it in various ways and it always appears another error message. Please help me
MyController
public function index()
{
$users = User::count();
$kelompok = Kelompok::count();
$anggota = Anggota::count();
$laporan = Anggota::select('kecamatan', Produk::raw('avg(total_sayur) as Total_Sayur, avg(total_buah) as Total_Buah,avg(total_ikan) as Total_Ikan, avg(total_ternak) as Total_Ternak'))
->leftjoin('produk', 'produk.anggota_id', '=', 'anggota.id')
->where('kecamatan', '=', 'Ngajum')
->GroupBy('kecamatan')
->get();
// return $laporan;
return view('Dashboard.index', compact('users', 'kelompok', 'anggota', 'laporan'));
}
View
<div class="row">
<div class="col-lg-3 col-6">
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>#currency($laporan->Total_Sayur)</h3>
<p>TOTAl KEMANFAATAN</p>
</div>
<div class="icon">
<i class="ion ion-pricetagg"></i>
</div>
More info <i class="fas fa-arrow-circle-right"></i>
</div>
</div>
</div>
Your solution start from here....
<div class="row">
<div class="col-lg-3 col-6">
#foreach($laporan as $item)
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>#currency($item->Total_Sayur)</h3>
<p>TOTAl KEMANFAATAN</p>
</div>
<div class="icon">
<i class="ion ion-pricetagg"></i>
</div>
More info <i class="fas fa-arrow-circle-right"></i>
</div>
#endforeach
</div>
</div>
Related
<div class="container mt-4 mb-4">
<div class="row">
<div class="col-lg-12">
<div id="blogCarousel" class="carousel slide" data-ride="carousel">
<div class="carousel-inner" role="listbox">
#foreach($reviews as $items)
<div class="carousel-item #if($loop->first) active #endif">
<div class="row">
#foreach($reviews as $review)
<div class="col-lg-4 ">
<a>
<div class="home1-img mt-3">
<?php
for($i=1;$i<6;$i++){
$check = '';
if($review->number_of_stars >= $i){
$check = 'checked';
}
echo '<span class="fa fa-star '.$check.'"></span>';
}
?>
<div class="home1-text mt-1" style="margin-bottom:30px;">
<p>{!! Illuminate\Support\Str::limit($review->customer_review,100) !!}</p>
<h5 class="text-color font-weight-bold">{{ $review->customer_name }}</h5>
</div>
</div>
</a>
</div>
#endforeach
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
</div>
I am getting all the records in all sides but I want 3 records in 1st slide then 3 records in 2nd slide and so on. I have tried many times but I am not able to fix it.
I am trying to show assigned users to the user I have made relationship b/w user and user_permission but I am facing an error.how to fix it thanks. please check this error https://flareapp.io/share/q5Y12O5X#F52 Can anyone provide me a solution that where I am wrong.
Database table
user_permission table
please see here https://ibb.co/7486n95
user table
please see here https://ibb.co/5jmqb0H
Controller
public function index()
{
$users=User::with('permission')->where('id' ,'!=' ,Auth::id())->paginate(6);
return view('index',compact('users'));
}
User Model
class User extends Authenticatable
{
public function permission()
{
return $this-
>hasMany('App\Users_permissions','user_Access_id','id');
}
}
Users_permissions Model
class Users_permissions extends Model
{
protected $table = 'user_permission';
protected $fillable = ['id','user_id', 'user_Access_id'];
public function user()
{
return $this->belongsTo('App\User','id');
}
}
Html View
<!-- Default box -->
<div class="card card-solid">
<div class="card-body pb-0">
<div class="row d-flex align-items-stretch">
#foreach($users->permission as $user)
<div class="col-12 col-sm-6 col-md-4 ">
<div class="card bg-light">
<div class="card-header text-muted border-bottom-0">
<div class="card-tools"> <span data-toggle="tooltip" title="3 New Messages"
class="badge badge-primary"></span>
</div>
</div>
<div class="card-body pt-0">
<div class="row">
<div class="col-7">
<h2 class="lead"><b>{{$user->name}}</b></h2>
<p class="text-muted text-sm"><b>Job: </b> {{$user->job}}</p>
<ul class="ml-4 mb-0 fa-ul text-muted">
<li class="small"><span class="fa-li"><i class="fas fa-lg fa-phone"></i></span> Phone
#: {{$user->phone_number}}</li>
</ul>
</div>
<div class="col-5 text-center">
<img src="{{url('public/assets/dist/img/user1-128x128.jpg')}}" alt="" class="img-
circle img-fluid">
</div>
</div>
</div>
<div class="card-footer">
<div class="text-left">
#if($user->isOnline())
<i class="fa fa-circle text-success"></i> Online#else
<i class="fa fa-circle text-default"></i> offline#endif</div>
<div class="text-right">
<a href="{{url('/chat',$user->id)}}" class="btn btn-sm bg-teal"> <i class="fas fa-
comments"></i><b> Chat</b>
</a>
</div>
</div>
</div>
</div>#endforeach</div>
</div>
<!-- /.card-body -->
<div class="card-footer">
<nav aria-label="Contacts Page Navigation">
<ul style="list-style-type:none;">
<li>{{$users->links()}}</li>
</ul>
</nav>
</div>
<!-- /.card-footer -->
</div>
<!-- /.card -->
Here, what you are trying to do this is you are directly accessing permission relationship from collection, this is why it is showing error. First you have to loop through users and inside that particular user permission relationship exist. So you have to loop through users model first.
Hope this helps:)
You are applying permissions to the collection of users, but only an individual user has permissions. You need to loop through all of your users, then access the users permissions:
#foreach($users as $user)
...
#foreach($user->permission as $permission)
{{$permission->name}}
#endforeach
#endforeach
In my controller function there is a foreach loop having query builder to get data from the database and after ending foreach loop, data is passed into views. This is looping more than 90 times.
class HomeController extends Controller {
public $menu;
public $msg;
public function __construct() {
$this->isEditor();
$this->menu = Config::get('constants.news.menu');
$this->msg = Config::get('constants.news');
}
public function index(Request $request) {
ini_set('max_execution_time', 300); //300 seconds = 5 minutes
//dd(session()->all());
$sessval = session()->all();
$uroles = DB::table('users_roles')
->where('id', Auth::user()->id)
->where('role_id','4')
//->toSql();
->get();
foreach($uroles as $key => $value)
{
$urole[]=$value->col-name;
$companiesid[]=$value->col-name2;
$rpending=DB::table('')
->select('')
->where('')
->where('')
->whereRaw("")
->count();
$abc+=$rpending;
$cactivities=DB::table('')
->select('')
->where('','=','')
->where('','=',$value->)
->where('','=',$value->)
->count();
$def+=$cactivities;
$pactivities=DB::table('')
->select('')
->where('','=','0')
->where('','=',$value->)
->where('','=',$value->)
->count();
$mno+=$pactivities;
$uactivities=DB::table('')
->select('')
->where('','=','0')
->where('','=',$value->)
->where('','=',$value->)
->whereBetween('due_date', [$tfrom, $to])
->count();
$ghi+=$uactivities;
$delayed=DB::table('')
->select('')
->where('','=','1')
->where('','=',$value->)
->where('','=',$value->)
->whereRaw('`actual_date`>`due_date` ')
//->toSql();
->count();
$jkl+=$delayed;
}
return view('view.name', compact('abc', 'def', 'ghi', 'jkl', 'mno'));
}
Any possible way to fetching the data in the background and when user loggedin it will render the view faster. Also i need to pass more data to the same view and that data is also getting from the database using forloop. How to reduce the loading time?. Please suggest any alternative way.
In view-
<div class="row">
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-green" style="background:green !important">
<div class="inner">
<h3>{{ $abc}}</h3>
<p>Comp</p>
</div>
<div class="icon">
<i class="fa fa-thumbs-up"></i>
</div>
More info <i class="fa fa-arrow-circle-right"></i>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-orange" style="background: darkorange !important">
<div class="inner">
<h3>{{ $def}}</h3>
<p>Delayed</p>
</div>
<div class="icon">
<i class="fa fa-book"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fa fa-
arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-red"style="background: red !important">
<div class="inner">
<h3>{{ $ghi}}</h3>
<p>Pen</p>
</div>
<div class="icon">
<i class="fa fa-clock-o"></i>
</div>
More info <i class="fa fa-arrow-circle-right"></i>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-xs-6">
<!-- small box -->
<div class="small-box bg-aqua">
<div class="inner">
<h3>{{ $jkl}}</h3>
<p>Pending</p>
</div>
<div class="icon">
<i class="fa fa-user-plus"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fa fa-
arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
</div>
The issue here is with inefficient database queries. Querying within a loop usually results in poor performance.
A better approach would be to fetch all related data to user roles using SQL Joins or Eloquent Relationships.
I have two tables called 'posts' and 'photos'. The 'photos' table store the images for the 'post'. A post can have many photos so the relationship is one-to-many. I've managed to create the store method, I already create the view to show a post with its photos as well. Below is the function :
public function show($titleslug) {
$post = Post::where('titleslug', '=', $titleslug)->first();
$images = $post->photos;
return view('dashboard/posts/show', compact('post','images', $post, $images));
}
The show view :
<div class="contentpanel">
<div class="row blog-content">
<div class="col-sm-12">
<div class="panel panel-default panel-blog">
<div class="panel-body">
<div class="panel-body">
<h3 class="blogsingle-title">{{$post->title}}</h3>
<ul class="blog-meta">
<li><i class="fa fa-clock-o"></i> Jan 02, 2014</li>
</ul>
<div class="mb20"></div>
{!! $post->content !!}
</div><!-- panel-body -->
<div class="mb20"></div>
</div><!-- panel-body -->
</div><!-- panel -->
</div><!-- col-sm-8 -->
</div><!-- row -->
<div class="row blog-content">
<div class="col-sm-12">
<div class="panel panel-default panel-blog">
<div class="panel-body">
<h3 class="blogsingle-title">This post featured images :</h3>
<div class="mb20"></div>
<?php foreach ($images as $i): ?>
<div class="col-xs-12 col-sm-4 col-md-3">
<div class="blog-item">
<img src="{{asset('image/'. $i->image)}}" class="img-responsive" alt="" style="height: 150px;"/>
<div class="blog-details">
<ul class="blog-meta">
<li><a class="btn btn-sm btn-warning" title="Edit" href="#"><i class="fa fa-edit"></i></a></li>
<form action="#" method="POST">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
<li>
<button type="submit" class="btn btn-sm btn-danger" title="Delete" onclick="return confirm('Are you sure deleting this photo ?');"><i class="fa fa-trash-o"></i></button>
</li>
</form>
</ul>
</div>
</div><!-- blog-item -->
</div><!-- col-xs-6 -->
<?php endforeach; ?>
</div>
<div class="panel-body">
<div class="alert alert-info fade in">
<p>
<button type="button" class="btn btn-info">Add New Images</button>
</p>
</div>
</div>
</div><!-- panel -->
</div>
</div>
</div><!-- contentpanel -->
I want to be able to delete the images from the show view, how to do that ? Do I need to create a function to it ? If so, then how will the function looks like ?
That's all and thanks, sorry for asking too much
First, edit your delete form in the view by adding :
...
<input type="hidden" name="image_id" value="{{ $images->id }}" /> // Assuming that photo id is in your $images object
...
Then, you could create a POST route image/delete associated to delete function from your controller to remove the expected image :
public function delete() {
$image_id = $request->only('image_id');
$image = Photo::where('id', '=', $image_id)->delete(); // Assuming that you have a Photo model
return view('dashboard/posts/show');
}
Here is my main view page :
the first class: item active ,
and another is only class: item
but i want foreach only class="col-sm-6" with two class item active and item ...
<div class="carousel-inner">
<div class="item active">
<div class="row">
<div class="col-sm-6">
<div class="col-item">
<div class="photo">
<img src="img/a.jpg" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>title</h5>
<h5 class="price-text-color">
Contact for price</h5>
</div>
<div class="rating hidden-sm col-md-6">
<i class="fa fa-bed"></i> <b>3</b>
<i class="fa fa-bath"></i> <b>2</b>
</div>
</div>
<div class="separator clear-left">
<p class="btn-details">
<i class="fa fa-list"></i>More details</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
</div>
</div>
<div class="item">
<div class="row">
<div class="col-sm-6">
<div class="col-item">
<div class="photo">
<img src="2.jpg" />
</div>
<div class="info">
<div class="row">
<div class="price col-md-6">
<h5>title</h5>
<h5 class="price-text-color">
Contact for price</h5>
</div>
<div class="rating hidden-sm col-md-6">
<i class="fa fa-bed"></i> <b>5</b>
<i class="fa fa-bath"></i> <b>3</b>
</div>
</div>
<div class="separator clear-left">
<p class="btn-details">
<i class="fa fa-list"></i>More details</p>
</div>
<div class="clearfix">
</div>
</div>
</div>
</div>
</div>
</div>
</div>
but when i foreach the div one is active class but i want one div is active but another is not . actually i want to foreach col-sm-6 class.. how to do this. first
I assume that you want the following:
for there to be one active item
for each item to contain several col-sm-6 elements, created via a php foreach loop
create item via a php foreach loop
<!-- language: lang-php -->
<?php $active_item = "active" ?>
<?php foreach($itemlist as $item): ?>
<div class="item <?php echo $active_item ?>">
<?php $active_item = "" ?>
<div class="row">
<?php foreach($item as $column): ?>
<div class="col-sm-6">
<!-- insert your logic here for creating your columns in a carousel -->
</div>
<?php endforeach ?>
</div>
</div>
<?php endforeach ?>
$active will append the active class to only the first instance of your carousel items.
I avoided using foreach($array as $key=>$value) and checking the key for whether the item is to be active, as your array may not have numerical keys that begin with 0.