So, Basically the Company can have one, two or no director and I want to display based on the company profile.
I want to display table like below (please don't mind the red border, I just want to highlight what I really want to changed in my table):-
and this is what I got:
this is my loop for displaying inside the table:
<table class="table table-borderless table-sm table_view2">
<thead>
<tr class="spaceSmall">
<td style="width:50%;padding-left: 10px;">NOTES TO ACCOUNT<br>Schedules referred to above and notes attached there to form an integral part of Balance Sheet.<br>This is the Balance Sheet referred to in our Report of even date.</td>
<td style="width:25%"></td>
<td style="width:25%"></td>
</tr>
</thead>
<tbody>
<tr class="spaceSmall">
<td style="padding-left: 25px;">{{ $auditor->auditor_name }}<br>{{ $auditor->qualification }}<br>Membership No. : {{ $auditor->membership_number }}</td>
#foreach($tasks->work->company->directors as $director)
#if($director->pivot->director_type == 'Both' || $director->pivot->director_type == 'Director')
#if(count($director) == 1)
<td></td>
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
#elseif(count($director) == 2)
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
#else
<td></td>
<td></td>
#endif
#else
<td></td>
<td></td>
#endif
#endforeach
</tr>
</tbody>
</table>
If company doesn't have director or if company has 1 director, then it is working perfectly, but if company has 2 directors then it try to insert at the 3rd and 4th column but I don't have that 4th column, If I removed the if condition inside that foreach then it's displaying like the 1st image but I have to check the director(s) they had.
Thanks in Advance
I got the answer, for anyone seeking the answer I just put this line outside the loop then everything works fine.
#php $countDirector = count($tasks->work->company->directors); #endphp
And inside my foreach
#if($countDirector == 1)
<td></td>
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
#elseif($countDirector == 2)
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
#else
<td></td>
<td></td>
#endif
Related
from my codes under, i want to set foreach enter another foreach as shown, i have two tables (reservation and courses ), and the objective is to find the status of course who have the same ID in two tables.
Tables:
Courses: (id_course, statutCourses)
reservation: (id_reserv, Location, Destination, Date, Phone, price)
thanks for helping me
#foreach ($reservations as $reservation)
<tr>
<td> {{ $reservation->id_reserv}}</td>
<td> {{ $reservation->Location}}</td>
<td> {{ $reservation->Destination }}</td>
<td> {{ $reservation->Date }}</td>
<td> {{ $reservation->Phone }}</td>
<td> {{ $reservation->price }}</td>
<td>
#foreach($courses as $course)
#if($course->id_course == $reservation->id_reserv)
<table style="margin-bottom: 15px;">
<tr>
<td style="padding-right: 10px;">Statut :</td>
<td>{{$course->statutCourses}}</td>
</tr>
</table>
#endif
#endforeach
</td>
</tr>
#endforeach
I'm sorry, I have a problem with my laravel pagination Gives me one by one page for example, in my table 16 row I make paginate (10), the pagination gives me in the first page from 1 to 10 and in the second page from 1 to 6 I want the normal pagination from 1 to 10 and from 11 to 16 any help, please
public function allappointmnts(){
$allapo=DB::table('bookappoitments')->orderBy('times.id')
->join('users','bookappoitments.users_id','users.id')
->join('times','bookappoitments.times_id','times.id')
->join('dates','bookappoitments.Dates_id','dates.id')
->paginate(10);
return view('admin.Managers.allappoinments',compact('allapo'));
}
in the blade page:
<div class="text-center">
{!! $allapo->links(); !!}
</div>
The table :
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
#foreach($allapo as $Appointments)
<td>{{ $loop->index+1 }}</td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td>
<a class="btn btn-success btn-mini deleteRecord " href="{{url('showbymanagment',$Appointments->id)}}">Show</a>
</td>
</tr>
#endforeach
Your problem is that you're using the current index of each loop - which will always be within the range of 1-10 of each page (since you have 10 elements per page).
You need to get the current page you're on using
$allapo->currentPage()
Then get the number of elements per page you got, using
$allapo->perPage()
Multiply these two, and it will be the base number for your pagination, meaning that its this number you should increment from.
The indexed table should then be
{{ $allapo->currentPage() * $allapo->perPage() + $loop->index }}
instead of
{{ $loop->index+1 }}
Then, to fix the heading-numbers (10 and 6 at the top), get the total number of results instead of the count of the page using
$allapo->total()
See the Laravel documentation for more details.
Not entirely sure, but you will need to write some sort of function to fix this.
Essentially you need to do this:
Get the page number (ex: 1)
Multiply it by the rows per page (ex: 10)
Add the iteration number
Subtract the per page number
function correct_pagination_numbers($cp, $pp, $counter)
{
$c = (($pp * $cp) + $counter) - $pp;
return $c;
}
Then you can call the function in your view like so:
<td>{{ correct_pagination_numbers($allapo->currentPage(), $allapo->perPage(), $loop->index) }}</td>
It would probably be the best solution to do this in a helper file. If you don't know how to create a helper file and autoload it, you can look here.
Try this code:
<?php $i = $lists->perPage() * ($lists->currentPage() - 1); ?>
<table class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Time</th>
<th>Employee</th>
<th>Name</th>
<th>Email</th>
<th>Company</th>
<th>Phone</th>
<th>Location</th>
<th>Remarks</th>
<th style="text-align: center;">Action</th>
</tr>
</thead>
<tbody>
<tr>
#foreach($allapo as $Appointments)
<td><?php $i++; ?>{{ $i }} </td>
<td>{{ $Appointments->Dates }}</td>
<td>{{ $Appointments->from_to }}</td>
<td>{{ $Appointments->name }}</td>
<td>{{ $Appointments->gustname }}</td>
<td>{{ $Appointments->gustemail }}</td>
<td>{{ $Appointments->gustcompany }}</td>
<td>{{ $Appointments->gustphone }}</td>
<td>{{ $Appointments->Location }}</td>
<td>{{ $Appointments->Remarks }}</td>
<td><a class="btn btn-success btn-mini deleteRecord " href="
{{url('showbymanagment',$Appointments->id)}}">Show</a></td>
</tr>
#endforeach
Try ths
#foreach($allapo as $key => $Appointments)
{{ $key + $allapo->firstItem() }}
#endforeach
to see the correct number change the line
<td>{{ $loop->index+1 }}</td>
to:
<td>{{ ($allapo->currentPage() - 1) * $allapo->perPage() + $loop->iteration }} <td>
I try to color table cell in laravel based on cell content but i keep getting this error:
"Illegal string offset 'Disponible' (View:
C:\Users\RAYLAN\Documents\CRMSAV\resources\views\
pagination_data.blade.php)
(View: C:\Users\RAYLAN\Documents\CRMSAV\re..."
This is my code:
#foreach($data as $row)
<tr>
<td>{{ $row->ID_Piece }}</td>
<td>{{ $row->Designation }}</td>
<td style="background-color: {{ $row->Status['Disponible'] }}">
{{ $row->Status }}
</td>
</tr>
{{$row->Status = array('Disponible' => '#FF0', 'N' => '#F0F')}}
#endforeach
<tr>
<td colspan="3" align="center">
{!! $data->links() !!}
</td>
</tr>
It's saying that there is no Disponible in this line:
{{$row->Status = array('Disponible' => '#FF0', 'N' => '#F0F')}}
Perhaps write this on the line above and check what is in $row->Status:
<?php
dd( $row->Status );
?>
But it looks a bit wierd, to be honest. Remember that the double-mustaches ( {{ $foobar }} ) are echoing the content. But you're assigning a value in there... To something that you're looping through?!
if your $row->Status['Disponsible'] is present in all the rows then try the below
<td style="background-color: {{ $row->Status['Disponible'] }}">
{{ $row->Status['Disponsible'] }}
</td>
EDIT:
try to substitute for your #foreachloop
#foreach($data as $row)
{{$row->Status = array('Disponible' => '#FF0', 'N' => '#F0F')}}
<tr>
<td>{{ $row->ID_Piece }}</td>
<td>{{ $row->Designation }}</td>
<td style="background-color: {{ $row->Status['Disponible'] }}">
{{ $row->Status['Disponible'] }}
</td>
</tr>
#endforeach
I decided to do it with Jquery, here is the working solution :
#foreach($data as $row)
<tr>
<td>{{ $row->ID_Piece }}</td>
<td>{{ $row->Designation }}</td>
<td id="status">{{ $row->Status }}</td>
</tr>
#endforeach
<tr>
<td colspan="3" align="center">
{!! $data->links() !!}
</td>
</tr>
<script type="text/javascript">
$(document).ready(function(){
$('#status').each(function(){
if ($(this).text() == 'N') {
$(this).css('background-color','#f00');
}
});
});
</script>
I am using Laravel 5 and I have a page which have some tables. My problem is, when there is no data in database, it shows nothing. I want it show 'Data is not found'. This first picture below is when the data is available in the database, and the second picture is when the data is unavailable in the database.
1.
2.
This is my code:
#if($candidateskill != '')
#foreach($candidateskill as $getData)
<tr>
<td>{{ $getData->SKILL_NAME }}</td>
<td align="center">{{ $getData->SKILL_LEVEL }}</td>
</tr>
#endforeach
#else
<td>Data is Not Found</td>
<td>Data is Not Found</td>
#endif
And this is the output of the null data:
Illuminate\Database\Eloquent\Collection Object ( [items:protected] =>
Array ( ) )
You can use the #forelse (https://laravel.com/docs/5.6/blade#loops)
#forelse($candidateskill as $getData)
<tr>
<td>{{ $getData->SKILL_NAME }}</td>
<td align="center">{{ $getData->SKILL_LEVEL }}</td>
</tr>
#empty
<tr><td colspan="2">No Data</td></tr>
#endforelse
Try this:
#if($candidateskill && !$candidateskill->isEmpty())
#foreach($candidateskill as $getData)
<tr>
<td>{{ $getData->SKILL_NAME }}</td>
<td align="center">{{ $getData->SKILL_LEVEL }}</td>
</tr>
#endforeach
#else
<tr>
<td>Data is Not Found</td>
</tr>
#endif
You need to evaluate your database variable if it exists, and if its not empty aka null.
If got the following database table:
Now I want to display the rows where where "inventory_warning" is greater then the "inventory" field. Like the second results as show below:
In my first example I do a where statement using Eloquent and try to get the rows, but it doesn't yield correct results (it retrieves all rows). My second example shows the check done with a PHP-if statement, which works but will be very inefficient when the table contains more data..
Shortened code:
<?php $products = Product::where('inventory_warning', '>', 'inventory')->get();?>
<tr>
<th colspan="3">First results:</th>
</tr>
#foreach($products as $product)
<tr>
<td># {{ $product->id }} - {{$product->item->name}}</td>
<td>{{ $product->inventory }}</td>
<td>{{ $product->inventory_warning }}</td>
</tr>
#endforeach
<?php $products = Product::all();?>
<tr>
<th colspan="3">Second results:</th>
</tr>
#foreach($products as $product)
#if($product->inventory_warning > $product->inventory)
<tr>
<td># {{ $product->id }} - {{$product->item->name}}</td>
<td>{{ $product->inventory }}</td>
<td>{{ $product->inventory_warning }}</td>
</tr>
#endif
#endforeach
What is going on here? Is this a possible Eloquent bug or am I doing something wrong?
Comparing two database fields isn't supported by the where function as far as i know.
You'll have to use whereRaw
Product::whereRaw('inventory_warning > inventory')->get();