I would wan to display month and data for payment_date only in a foreach loop in view.blade.php.
#foreach ($alert as $key=>$data)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ $data->payment_date }}</td>
<td><span class="badge bg-danger">{{ $data->status }}</span></td>
<td> <i class="bi bi-envelope-fill"></i>
</td>
</tr>
#endforeach
Hereby I include the datatype:
Short way (not recommended)
#foreach ($alert as $key=>$data)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ \Carbon\Carbon::createFromFormat('Y-m-d', $data->payment_date)->format('m-d') }}</td>
<td><span class="badge bg-danger">{{ $data->status }}</span></td>
<td> <i class="bi bi-envelope-fill"></i>
</td>
</tr>
#endforeach
Laravel way (Recommended)
Add cast to the eloquent model class.
protected $casts = [
'payment_date' => 'date',
];
after that you can do this
#foreach ($alert as $key=>$data)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $data->tenant_name}}</td>
<td>{{ $data->property_name}}</td>
<td>RM {{ $data->amount}}</td>
<td>{{ $data->payment_date->format('m-d') }}</td>
<td><span class="badge bg-danger">{{ $data->status }}</span></td>
<td> <i class="bi bi-envelope-fill"></i>
</td>
</tr>
#endforeach
I want to use 2 FOREACH in 1 table body VIEW laravel
like this for the EXCEL.VIEW.BLADE code
<table>
<thead>
<tr>
<th>Booking Status</th>
<th>CreatedAT</th>
<th>New row</th>
</tr>
</thead>
<tbody>
#foreach($datas as $hasil)
foreach($pp as $res)
<tr>
<td>{{ $hasil->BookingStatus }}</td>
<td>{{ $hasil->DeliveryCharge }}</td>
<td>{{ $res->BookingStatus }}</td>
</tr>
#endforeach
#endforeach
</tbody>
</table>
and for the code in the controller like this
$data = TR_BookingHeader::where('LogisticId', $this->qty)->get();
$pp = TR_BookingHeader::all();
return view('Excel', [
'datas' => $data, 'pp' => $pp
]);
Try this one
<tbody>
#foreach($datas as $hasil)
#foreach($pp as $res)
<tr>
<td>{{ $hasil->BookingStatus }}</td>
<td>{{ $hasil->DeliveryCharge }}</td>
<td>{{ $res->BookingStatus }}</td>
</tr>
#endforeach
#endforeach
</tbody>
Another example
[
state
college
college
state
college
college
college
...
]
#foreach ($states as $state => $colleges)
<h1 style="center">{{ $state }}</h1>
<ul class="nospace clear">
#foreach ($colleges as $college)
<li class="one_quarter first">
<h3 class="center">{{ $college->college }}</h3>
</li>
#endforeach
</ul>
#endforeach
I am using Laravel 5.8 to create an App. When I wanted to display the view, it generated an error as shown below:
syntax error, unexpected ')', expecting '['
Controller
public function serviceOverview(Request $request)
{
$data['title'] = 'Subscription Overview';
$serviceoverviews = DB::table("service_package")
->join('services', 'services.id', '=', 'service_package.service_id')
->join('service_type', 'service_type.id', '=', 'services.service_type')
->select('service_package.title as service_id', 'service_package.title as package_name', DB::raw("DATE(service_package.created_at) as created_at"), 'service_package.price', 'service_package.days','services.name as service_name','service_type.name as service_type');
$render=[];
if(isset($request->package_name))
{
$serviceoverviews=$serviceoverviews->where('serviceoverviews','like','%'.$request->serviceoverviews.'%');
$render['package_name']=$request->package_name;
}
if(isset($request->service_id))
{
$serviceoverviews=$serviceoverviews->where('service_id',$request->service_id);
$render['service_id']=$request->service_id;
}
$serviceoverviews= $serviceoverviews->orderBy('created_at','DESC');
$serviceoverviews= $serviceoverviews->paginate(15);
$serviceoverviews= $serviceoverviews->appends($render);
$data['serviceoverviews'] = $serviceoverviews;
return view('report.serviceOverview',$data);
}
In the Controller, I tried to do some filtering. Also, I did raw query.
View
<div class="box box-primary">
<div class="box-header with-border">
#if(Session::has('flash_message'))
<div class="alert alert-success">
{{ Session::get('flash_message') }}
</div>
#endif
#if(count($detailsubscriptions))
<table class="table table-bordered table-hover table-striped table-condesed" id="commenter_info_table">
<caption></caption>
<thead>
<tr>
<td>#</td>
<td>Service</td>
<td>Package</td>
<td>Service Type</td>
<td>Date</td>
<td>Price</td>
<td>Days</td>
</tr>
</thead>
<tbody>
#foreach($serviceoverviews as $key => serviceoverview)
<tr>
<td>{{ ++$key }}</td>
<td>{{ serviceoverview->service_name }}</td>
<td>{{ $serviceoverview->package_name }}</td>
<td>{{ $serviceoverview->service_type }}</td>
<td>{{ serviceoverview->created_at }}</td>
<td>{{ $serviceoverview->price }}</td>
<td>{{ $serviceoverview->days }}</td>
</tr>
#endforeach
<tr>
<td colspan="8">
{{ $serviceoverview->links() }}
</td>
</tr>
</tbody>
</table>
#else
<div class="row text-center">
<h2>No Service Overview to show</h2>
</div>
#endif
</div>
</div>
I tried to check the code, but found nothing. How do I resolve this issue
You have missed a $ from the $serviceoverview variable in your blade #foreach. Change:
#foreach($serviceoverviews as $key => serviceoverview)
To
#foreach($serviceoverviews as $key => $serviceoverview)
Here is the full code updated with changes. Please refer to this
Controller.php
public function serviceOverview(Request $request)
{
$builder = DB::table("service_package")
->join('services', 'services.id', '=', 'service_package.service_id')
->join('service_type', 'service_type.id', '=', 'services.service_type')
->select('service_package.title as service_id', 'service_package.title as package_name', DB::raw("DATE(service_package.created_at) as created_at"), 'service_package.price', 'service_package.days','services.name as service_name','service_type.name as service_type');
if($request->filled('package_name'))) {
$builder = $builder->where('serviceoverviews','like','%'.$request->serviceoverviews.'%');
}
if(isset($request->service_id))
{
$builder=$builder->where('service_id',$request->service_id);
}
$serviceoverviews = $builder->orderBy('created_at','DESC')->paginate(15);
$data = [
'title' => 'Subscription Overview',
'serviceoverviews' => $serviceoverviews
];
return view('report.serviceOverview', $data);
}
Now change your view code like this.
view.blade.php
<table class="table table-bordered table-hover table-striped table-condesed" id="commenter_info_table">
<caption></caption>
<thead>
<tr>
<td>#</td>
<td>Service</td>
<td>Package</td>
<td>Service Type</td>
<td>Date</td>
<td>Price</td>
<td>Days</td>
</tr>
</thead>
<tbody>
#foreach($serviceoverviews as $key => $serviceoverview)
<tr>
<td>{{ ++$key }}</td>
<td>{{ $serviceoverview->service_name }}</td>
<td>{{ $serviceoverview->package_name }}</td>
<td>{{ $serviceoverview->service_type }}</td>
<td>{{ serviceoverview->created_at }}</td>
<td>{{ $serviceoverview->price }}</td>
<td>{{ $serviceoverview->days }}</td>
</tr>
#endforeach
<tr>
<td colspan="8">
{{ $serviceoverview->appends(\Request::all())->links() }}
</td>
</tr>
</tbody>
</table>
You are using serviceoverview in place of $serviceoverview in view file. That would be an issue.
You have made some typo and one logical error.
Change
#foreach($serviceoverviews as $key => serviceoverview) to #foreach($serviceoverviews as $key => $serviceoverview)
<td>{{ serviceoverview->service_name }}</td> to <td>{{ $serviceoverview->service_name }}</td>
You have put {{ $serviceoverview->links() }} out side of the foreach loop
I am creating a simple crud application with file upload. But i have problems in displaying the thumbnail in view(index.blade.php). All images in database are displayed in each book instead of displaying one image in one book. Here is my controller.
public function index()
{
$books=UploadedFile::all();
$files=Upload::all();
return view('books.index',compact('books','files'));
}
and my index.blade.php
<table class="table table-striped table-bordered table-hover">
<thead>
<tr class="bg-info">
<th>Id</th>
<th>ISBN</th>
<th>Title</th>
<th>Author</th>
<th>Publisher</th>
<th>Thumbs</th>
<th colspan="3">Actions</th>
</tr>
</thead>
<tbody>
#foreach ($books as $book )
<tr>
<td>{{ $book->id }}</td>
<td>{{ $book->isbn }}</td>
<td>{{ $book->title }}</td>
<td>{{ $book->author }}</td>
<td>{{ $book->publisher }}</td>
<td>
#foreach ($files as $file )
<img src="{{asset('uploads/'.$file->filename)}}" height="40" width="50">
#endforeach
</td>
<td>Details</td>
<td>Update</td>
<td>
{!! Form::open(['method' => 'DELETE', 'route'=>['books.destroy', $book->id]]) !!}
{!! Form::submit('Delete', ['class' => 'btn btn-danger']) !!}
{!! Form::close() !!}
</td>
</tr>
#endforeach
</tbody>
</table>
I separated the table for the filename from the rest of the fields. and here is the result--
I've got the following code which shows my clubs fixtures/results list for upcoming games:
<div class="row">
<div class="col-md-10 col-md-offset-1">
<span id="hide" class="first">1st XV Fixtures/Results</span><span id="show">2nd XV Fixtures/Results</span>
<table class="table table-bordered table-hover">
<tr>
<th>Date</th>
<th>Venue</th>
<th>Opposition</th>
<th>Kick Off</th>
<th>Type</th>
<th>Score</th>
<th>Result</th>
</tr>
#foreach ($fixtures as $fix)
#if($fix['team'] === 1)
<tr class="clickableRow success league_table" href="{{ action('DynamicPages#match',[$fix['id']]) }}">
<td>{{ date("d/m/Y",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['venue'] }}</td>
<td>{{ $fix['opposition'] }}</td>
<td>{{ date("H:i",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['type'] }}</td>
#foreach($results as $result)
#if($result['match_id']=== $fix['id'])
#if(!empty($result['score']))
<td>{{ $result['score'] }}</td>
<td>{{ $result['result'] }}</td>
#else
<td> </td>
<td> </td>
#endif
#endif
#endforeach
</tr>
#else
<tr class="clickableRow danger merit-table" style="display:none;" href="{{ action('DynamicPages#match',[$fix['id']]) }}">
<td>{{ date("d/m/Y",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['venue'] }}</td>
<td>{{ $fix['opposition'] }}</td>
<td>{{ date("H:i",strtotime($fix['mdate'])) }}</td>
<td>{{ $fix['type'] }}</td>
#foreach($results as $result)
#if($result['match_id']=== $fix['id'])
#if(isset($result['score']))
<td>{{ $result['score'] }}</td>
<td>{{ $result['result'] }}</td>
#else
<td> </td>
<td> </td>
#endif
#endif
#endforeach
</tr>
#endif
#endforeach
</table>
</div>
</div>
I want it to show the score from the DB, but if thats blank, then just to show a blank table with a background colour. However, it's simple showing nothing so when I look at it, it shows a white space.
Can anyone help?