Laravel foreach in if statement - laravel

This is my code
#if ($story)
<table class="table-auto my-3 w-full">
<thead class="justify-between">
<tr class="bg-gray-800">
<th class="px-16 py-2">
<span class="text-gray-300">#Id</span>
</th>
<th class="px-16 py-2">
<span class="text-gray-300">Name</span>
</th>
<th class="px-16 py-2">
<span class="text-gray-300">Description</span>
</th>
<th class="px-16 py-2">
<span class="text-gray-300">Actions</span>
</th>
</tr>
</thead>
<tbody class="bg-gray-200">
#foreach ($story as $item)
<tr class="bg-white border-4 border-gray-200">
<td class="px-16 py-2 flex flex-row items-center">
{{ $item->id }}
</td>
<td>
{{ Str::words($item->name, 3, $end = '...') }}
</td>
<td class="px-16 py-2">
{!! Str::words($item->description, 6, $end = '...') !!}
</td>
<td class="px-16 py-2">
<a href="{{ route('dashboard.story.edit', $item->id) }}">
<button class="bg-blue-500 text-white px-4 py-1 border rounded-md hover:bg-white hover:border-blue-500 hover:text-black">
Edit
</button>
</a>
</td>
</tr>
#endforeach
</tbody>
</table>
#else
<p>No results found</p>
#endif
This is my controller
public function index()
{
$story = Story::paginate(10);
return view('admin.story.index', ['story' => $story]);
}
I'm using Laravel 8 and I don't want to show table headers when the value is null. Laravel showing tables headers and not showing the 'No results found' message.
Any help would be appreciated.

when you use paginate, your data split. so if you want check this data empty or not just use
#if( $story->total() )
just replace it with
#if ( $story )

Related

Laravel dompdf taking too much time to generate and download a pdf

I'm recently working on report generation for simple 2 records from database. For generating this report i'm using Laravel dompdf package, but it's taking too long time to download which is not expected. Code I used is below:
$pdf = PDF::loadView('dashboard.sales-report', compact('sales'));
$pdf->setPaper('A4', 'portrait');
$sales_report_file_name = "daily_sales_".date('Y-m-d').".pdf";
return $pdf->download($sales_report_file_name);
and using css inside our view page. But only two records taking more than 2 minutes. Could anyone please help me on it? Thanks in advance.
Blade file code:
#extends('layouts.invoice_master')
#section('content')
#php
$total_discount = 0;
$total_advance = 0;
$total_net_sum = 0;
$total = 0;
#endphp
<!-- START CONTAINER FLUID -->
<div class=" container-fluid container-fixed-lg">
<!-- START card -->
<div class="card card-default m-t-20">
<div class="card-body">
<!-- Define header and footer blocks before your content -->
<header>
<p>{{ $report_for }} </p>
<p>{{ $report_for_date }}</p>
<p>{{ $report_for_month }}</p>
</header>
<div class="invoice padding-50 sm-padding-10" style="padding-left:unset !important;">
<div class="row">
<div class="col-lg-3" style="padding-left:5px !important;">
<img style="width: 200px;margin-bottom: 20px" alt="" class="invoice-logo" src="{{ asset('uploads/company/'.$company_details->id.'/receipt_logo/'.$company_details->receipt_logo)}}">
</div>
<div class="col-lg-8">
<address class="m-t-10">
#if($out_let)
{{ $out_let[0]->name }}
<br>{{ $out_let[0]->location }}
<br>{{ $out_let[0]->address }}
<br>{{ $out_let[0]->city }} , {{ $out_let[0]->zip }}
<br>Contact: {{ $out_let[0]->phone }}
<br>
#endif
</address>
</div>
</div>
<div class="clearfix"></div>
<div class="table-responsive table-invoice">
<table class="table m-t-25">
<thead>
<tr>
<th class="text-center">Date</th>
<th class="text-center">Invoice</th>
<th class="text-center">Customer</th>
<th class="text-center">Total</th>
<th class="text-center">Discount</th>
<th class="text-center">Net.Sum</th>
<th class="text-center">Advance</th>
<th class="text-center">Remain</th>
<th class="text-center">Currency</th>
</tr>
</thead>
<tbody>
#if( $sales )
#foreach( $sales as $sale )
<tr>
<td class="text-center">
{{ $sale->created_at }}
</td>
<td class="text-center">
<p class="text-black">
#if(isset($sale->invoice_prefix_id))
{{
App\InvoicePrefix::find($sale->invoice_prefix_id)->name
}}-{{ $sale->invoice_no
}}
#else
{{ $sale->invoice_no }}
#endif
</p>
</td>
<td class="text-center">
#if(isset($sale->customer_id))
{{ App\Customer::find($sale->customer_id)->first_name }}
{{ App\Customer::find($sale->customer_id)->last_name }}
( {{ App\Customer::find($sale->customer_id)->customer_no}} )
#else
Guest
#endif
</td>
<td class="text-center">
#php
$total = $sale->sub_total + $sale->vat_amount;
echo number_format($total);
#endphp
</td>
<td class="text-center">
#php
$total_discount = number_format($total_discount + ($sale->discount_amount + $sale->coupon_discount_amount));
echo number_format($sale->discount_amount + $sale->coupon_discount_amount);
#endphp
</td>
<td class="text-center">
#php
echo number_format($sale->net_amount);
#endphp
</td>
<td class="text-center">
#if(isset($sale->id))
#php
$advance = App\SalePaid::where('sale_id', $sale->id)->sum('paid_amount');
if($advance <= $sale->net_amount){
echo number_format($advance);
}else{
echo number_format($sale->net_amount);
$advance = $sale->net_amount;
}
$total_advance = $total_advance + $advance;
#endphp
#endif
</td>
<td class="text-center">
#php
echo number_format(max(($sale->net_amount - App\SalePaid::where('sale_id', $sale->id)->sum('paid_amount')), 0));
$total_net_sum = $total_net_sum + $sale->net_amount;
#endphp
</td>
<td class="text-center">
#if(isset($sale->company_currency_id))
{{
App\Currency::find(App\CompanyCurrency::find($sale->company_currency_id)->currency_id)->code
}}
#else
N/A
#endif
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</div>
<br>
<div class="panel-heading title-color">
<table class="table table-hover table-heading" id="tableWithSearch">
<tbody class="table-body">
<tr>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text semi-bold">Discount: BDT
#php
echo number_format($total_discount);
#endphp</h5>
</td>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text semi-bold">Advance: BDT
#php
echo number_format($total_advance);
#endphp
</h5>
</td>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text semi-bold">Remain Sum: BDT
#php
echo number_format(max(($total_net_sum - $total_advance), 0));
#endphp
</h5>
</td>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text bold">Net. Sum: BDT
#php
echo number_format($total_net_sum);
#endphp
</h5>
</td>
</tr>
</tbody>
</table>
</div><br/>
<div class="stamp-signature">
<div class="authority-signature">
Printed By: {{ Auth::user()->userDetail ? Auth::user()->userDetail->first_name : '' }} {{ Auth::user()->userDetail ? Auth::user()->userDetail->last_name : '.......................' }}
</div>
<div class="customer-signature">
Authorized By: .......................
</div>
</div>
<div class="clear"></div>
<br>
<br>
<div>
<span class="bold hint-text">Notes: </span>
<span class="small hint-text">This report generated on Date: {{ $report_generated_on }}. Please issue company stamp and sign in above section.
</span>
</div>
<div class="footer-border" style="width: 100% !important;"></div>
<footer>
<div class="footer-logo">
<img style="width: 80px; height: 22px;" alt="" class="invoice-logo" src="{{ asset('uploads/company/'.$company_details->id.'/receipt_logo/50x50/'.$company_details->receipt_logo)}}">
</div>
#if($out_let)
<div class="footer-info-text">
| <span class="m-l-70 text-black sm-pull-right"> {{ $out_let[0]->name }} </span>
| <span class="m-l-70 text-black sm-pull-right">
{{ $out_let[0]->phone }}</span> <br/><br/>
<span class="m-l-70 text-black sm-pull-right"> Software By: {{ env('APP_URL')}}</span><br/>
</div>
#endif
</footer>
</div>
</div>
</div>
<!-- END card -->
</div>
<!-- END CONTAINER FLUID -->
#endsection
Here comes controller function:
/**
* Generate daily sales report for logged user's Outlet
*
* #return Pdf generated report
*/
protected function dailyReport(){
$company_details = $this->getCompanyDetails();
$report_for = "Daily Sales Report";
$report_for_date = "Date: ".date('Y-m-d H:i:s');
$report_for_month = "";
$from_date = $today_date = date('Y-m-d');
$report_generated_on = date('Y-m-d H:i:s');
$out_let = OutLet::where('id',$_COOKIE['out_let_id'])->get();
$sales = Sale::whereDate('sale_date',date('Y-m-d'))->where('out_let_id',$_COOKIE['out_let_id'])->get();
$pdf = PDF::loadView('dashboard.sales-report', compact('out_let','sales', 'report_for','report_for_date','from_date','today_date','report_for_month','report_generated_on','company_details'));
// (Optional) Setup the paper size and orientation
$pdf->setPaper('A4', 'portrait');
// download PDF file with download method
$sales_report_file_name = "daily_sales_".date('Y-m-d').".pdf";
return $pdf->download($sales_report_file_name);
}
Here comes new blade file code where no DB query:
#extends('layouts.invoice_master')
#section('content')
#php
$total_discount = 0;
$total_advance = 0;
$total_net_sum = 0;
$total = 0;
#endphp
<!-- START CONTAINER FLUID -->
<div class=" container-fluid container-fixed-lg">
<!-- START card -->
<div class="card card-default m-t-20">
<div class="card-body">
<!-- Define header and footer blocks before your content -->
<header>
<p>{{ $report_for }} </p>
<p>{{ $report_for_date }}</p>
<p>{{ $report_for_month }}</p>
</header>
<div class="invoice padding-50 sm-padding-10" style="padding-left:unset !important;">
<div class="row">
<div class="col-lg-3" style="padding-left:5px !important;">
<img style="width: 200px;margin-bottom: 20px" alt="" class="invoice-logo" src="{{ asset('uploads/company/'.$company_details->id.'/receipt_logo/'.$company_details->receipt_logo)}}">
</div>
<div class="col-lg-8">
<address class="m-t-10">
#if($out_let)
{{ $out_let[0]->name }}
<br>{{ $out_let[0]->location }}
<br>{{ $out_let[0]->address }}
<br>{{ $out_let[0]->city }} , {{ $out_let[0]->zip }}
<br>Contact: {{ $out_let[0]->phone }}
<br>
#endif
</address>
</div>
</div>
<div class="clearfix"></div>
<div class="table-responsive table-invoice">
<table class="table m-t-25">
<thead>
<tr>
<th class="text-center">Date</th>
<th class="text-center">Invoice</th>
<th class="text-center">Customer</th>
<th class="text-center">Total</th>
<th class="text-center">Discount</th>
<th class="text-center">Net.Sum</th>
<th class="text-center">Advance</th>
<th class="text-center">Remain</th>
<th class="text-center">Currency</th>
</tr>
</thead>
<tbody>
#if( $sales )
#foreach( $sales as $sale )
<tr>
<td class="text-center">
{{ $sale->created_at }}
</td>
<td class="text-center">
<p class="text-black">
#if(isset($sale->invoice_prefix_id))
Saj-{{ $sale->invoice_no
}}
#else
{{ $sale->invoice_no }}
#endif
</p>
</td>
<td class="text-center">
#if(isset($sale->customer_id))
abu taher
#else
Guest
#endif
</td>
<td class="text-center">
#php
$total = $sale->sub_total + $sale->vat_amount;
echo number_format($total);
#endphp
</td>
<td class="text-center">
#php
$total_discount = number_format($total_discount + ($sale->discount_amount + $sale->coupon_discount_amount));
echo number_format($sale->discount_amount + $sale->coupon_discount_amount);
#endphp
</td>
<td class="text-center">
#php
echo number_format($sale->net_amount);
#endphp
</td>
<td class="text-center">
#if(isset($sale->id))
#php
$advance = "250";
if($advance <= $sale->net_amount){
echo number_format($advance);
}else{
echo number_format($sale->net_amount);
$advance = $sale->net_amount;
}
$total_advance = $total_advance + $advance;
#endphp
#endif
</td>
<td class="text-center">
#php
echo number_format(max(($sale->net_amount - 250), 0));
$total_net_sum = $total_net_sum + $sale->net_amount;
#endphp
</td>
<td class="text-center">
#if(isset($sale->company_currency_id))
BDT
#else
N/A
#endif
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
</div>
<br>
<div class="panel-heading title-color">
<table class="table table-hover table-heading" id="tableWithSearch">
<tbody class="table-body">
<tr>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text semi-bold">Discount: BDT
#php
echo number_format($total_discount);
#endphp</h5>
</td>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text semi-bold">Advance: BDT
#php
echo number_format($total_advance);
#endphp
</h5>
</td>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text semi-bold">Remain Sum: BDT
#php
echo number_format(max(($total_net_sum - $total_advance), 0));
#endphp
</h5>
</td>
<td class="v-align-middle">
<h5 class="font-montserrat all-caps small hint-text bold">Net. Sum: BDT
#php
echo number_format($total_net_sum);
#endphp
</h5>
</td>
</tr>
</tbody>
</table>
</div><br/>
<div class="stamp-signature">
<div class="authority-signature">
Printed By: ABU TAHER
.......................
</div>
<div class="customer-signature">
Authorized By: .......................
</div>
</div>
<div class="clear"></div>
<br>
<br>
<div>
<span class="bold hint-text">Notes: </span>
<span class="small hint-text">This report generated on Date: {{ $report_generated_on }}. Please issue company stamp and sign in above section.
</span>
</div>
<div class="footer-border" style="width: 100% !important;"></div>
<footer>
<div class="footer-logo">
<img style="width: 80px; height: 22px;" alt="" class="invoice-logo" src="{{ asset('uploads/company/'.$company_details->id.'/receipt_logo/50x50/'.$company_details->receipt_logo)}}">
</div>
#if($out_let)
<div class="footer-info-text">
| <span class="m-l-70 text-black sm-pull-right"> {{ $out_let[0]->name }} </span>
| <span class="m-l-70 text-black sm-pull-right">
{{ $out_let[0]->phone }}</span> <br/><br/>
<span class="m-l-70 text-black sm-pull-right"> Software By: {{ env('APP_URL')}}</span><br/>
</div>
#endif
</footer>
</div>
</div>
</div>
<!-- END card -->
</div>
<!-- END CONTAINER FLUID -->
#endsection
Finally I solved the issue myself. The problem was in img tag image loading path. Previously using below img tag where path was wrong according to pdf generation and due to that system was unable to load the image, so it was taking too much time:
Previous img tag:
<img style="width: 80px; height: 22px;" alt="" class="invoice-logo" src="{{ asset('uploads/company/'.$company_details->id.'/receipt_logo/50x50/'.$company_details->receipt_logo)}}">
New img tag where image path is different than upper one, and here everything working fine including time.
<img style="width: 80px; height: 22px;" alt="" class="invoice-logo" src="{{ public_path().'/uploads/company/'.$company_details->id.'/receipt_logo/50x50/'.$company_details->receipt_logo }}">

Return with message not show previous data on show blade

i have a problem where when i submit edit and redirect back the show page with message, the previous table not showing.
This is the previous table
This is after submit where only back to the previous page and show message not the details.
the page only show the successful message but not the details of the case as the previous case.
This is my feedbackController for show() and update() class
public function show(Feedback $feedback){
$feedback->load('user');
return view('feedback.show',compact('feedback'));
}
public function update(Request $request, Feedback $feedback){
$request->validate([
'status' => 'required|not_in:0',
'remark' => ['string', 'max:255', 'nullable']
]);
$feedback->fill($request->post())->save();
return redirect()->back()->with('success','Feedback updated successfully');
}
This is my blade file
#if (session('success'))
<div class="alert alert-success" role="alert">
<button type="button" class="close" data-dismiss="alert">×</button>
{{ session('success') }}
</div>
#else
<h2><i class="fa fa-arrow-left" aria-hidden="true"></i> Case ID - {{ $feedback->id }}</h2>
<div class="table-responsive-lg pt-4">
<table class="table table-active table-borderless table-hover" style="width:100%;border-radius: 5px">
<tr>
<th scope="col" style="width:10%">Name</th>
<td>{{ $feedback->user->name }}</td>
</tr>
<tr>
<th scope="col" style="width:10%">Title</th>
<td>{{ $feedback->title }}</td>
</tr>
<tr>
<th scope="col" style="width:10%">Message</th>
<td>{{ $feedback->details }}</td>
</tr>
<tr>
<th scope="col" style="width:10%">Created at</th>
<td>{{ $feedback->created_at }}</td>
</tr>
<tr>
<th scope="col" style="width:10%">Reply</th>
<td>Email</td>
</tr>
<tr>
<form action="{{ route('feedback.update',$feedback->id) }}" method="post">
#csrf
#method('PUT')
<th scope="col" style="width:10%">Status</th>
<td>
<select name="status" class="custom-select #error('status') is-invalid #enderror">
<option #if(( old('status') ?? $feedback->status)==NULL)selected
#endif value="0">Choose...</option>
<option #if(( old('status') ?? $feedback->status)==1)selected
#endif value="1">Received</option>
<option #if(( old('status') ?? $feedback->status)==2)selected
#endif value="2">Reply</option>
</select>
#error('status')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</td>
</tr>
<tr>
<th scope="col" style="width:10%">Remark</th>
<td>
<textarea name="remark" class="form-control #error('remark') is-invalid #enderror" placeholder="Write your remark here" rows="4">{{ old('remark') ?? $feedback->remark }}</textarea>
#error('remark')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</td>
</tr>
<tr>
<th scope="col" style="width:10%"></th>
<td style="text-align: right;width:100%">
<button type="submit" class="btn btn-primary">Save</button>
</form>
</td>
</tr>
<tbody>
</tbody>
</table>
I hope anyone can help me :)
According to your blade file you created session success message in if and html code in else file why?
Please don't use else part if you want to show both blade file and success message.
In your case if success message will come then else part will not show
#if (Session::has('success'))
<div class="alert alert-success">
<ul>
<li>{{ Session::get('success') }}</li>
</ul>
</div>
#endif
Try Accessing like this

Form select is showing entire row not one column

I am trying to make a filter for my table but i see a problem there. Maybe the problem is from table structure couse i fetch all structure as it is on mysql. Does anyone help to make this filter in right way.
The collapse content under comment is the head i display when i want to filter
<table class="table table-hover align-middle mb-0">
<thead class="">
<tr>
<th><input type="checkbox" class="form-check-input" v-model="selectAll" title="Select All"></th>
<th v-if="!isHidden[index]" v-for="(header, index) in visibleHeaders" :key="index" scope="col">
{{ header }}
</th>
<th>ACTION</th>
</tr>
</thead>
<!-- Collapsed content ./ -->
<thead class="collapse" id="collapseFilter">
<tr>
<th>#</th>
<th v-for="(header, index) in visibleHeaders" scope="col">
<select id="" class="form-select" >
<option v-for="column in leads">
<div v-for="(atr, key, index) in column">
{{atr}}
</div>
</option>
</select>
</th>
</tr>
</thead>
<!-- ./ Collapse contet -->
<tbody>
<tr v-show="leads.length" v-for="column in leads" >
<td>
<input type="checkbox" class="form-check-input" v-model="selected" :value="column.id" />
</td>
<td v-if="!isHidden[index]" v-for="(atr, key, index) in column">
<div v-if="atr == 'new'">
<span class="badge bg-info">{{ atr }}</span>
</div>
<div v-else-if="atr == 'contract'">
<span class="badge bg-success">{{ atr }}</span>
</div>
<div v-else>
<span >{{ atr }}</span>
</div>
</td>
<td>
<button #click="editLead(column.id)" type="button" class="btn btn-sm btn-secondary" data-mdb-toggle="modal" data-mdb-target="#editLeadModal" >
<i class="fa-solid fa-eye"></i>
</button>
</td>
</tr>
<tr v-show="!leads.length">
<td colspan="12" class="text-center">Sorry :( No data found.</td>
</tr>
</tbody>
</table>
If i try to loop only v-for="column in lead"

Blade filter data depending on the authenticated user's role

I'm trying to make a school management system with laravel and jQuery. Currently it's working ok with admin as logged in user. But I'm having trouble to create the blade for when the parents are logged in.
I've in a StudentController the index formula below
if( Auth::user()->is_parent ){
$students = Student::with(['status', 'birth_country', 'main_nationality', 'secondary_nationality', 'spoken_languages', 'student_categories', 'p_1_relationship',
'p_1_main_nationality', 'p_1_pref_comm_lang', 'p_2_relationship', 'p_2_main_nationality', 'p_2_pref_comm_lang', 'academic_session',
'academic_formation', 'academic_class', 'registration_type', 'academic_section', 'option_1', 'option_2', 'option_3', 'option_4', 'option_5',
'option_6', 'option_7', 'option_8', 'option_9', 'option_10', 'user_student', 'created_by'])
->where('p_1_email', '=', Auth::user()->email)
->orWhere('p_2_email', '=', Auth::user()->email)
->get();
} else{
$students = Student::with(['status', 'birth_country', 'main_nationality', 'secondary_nationality', 'spoken_languages', 'student_categories', 'p_1_relationship',
'p_1_main_nationality', 'p_1_pref_comm_lang', 'p_2_relationship', 'p_2_main_nationality', 'p_2_pref_comm_lang', 'academic_session',
'academic_formation', 'academic_class', 'registration_type', 'academic_section', 'option_1', 'option_2', 'option_3', 'option_4', 'option_5',
'option_6', 'option_7', 'option_8', 'option_9', 'option_10', 'user_student', 'created_by'])
->get();
}
$statuses = Status::where('module', 'Academic Registration')->get();
$countries = Country::get();
$languages = Language::get();
$categories = Category::where('head_category_id',24)->get();
$relationships = Relationship::get();
$academic_sessions = AcademicSession::get();
$academic_formations = AcademicFormation::get();
$academic_classes = AcademicClass::get();
$types = Type::where('module', 'Academic Registration')->get();
$academic_sections = AcademicSection::get();
$academic_subjects = AcademicSubject::get();
$users = User::get();
return view('app.students.index', compact('academic_classes', 'academic_formations', 'academic_sections', 'academic_sessions', 'academic_subjects', 'categories',
'countries', 'languages', 'relationships', 'statuses', 'types', 'students', 'users'));
And my index blade ,
#if ( Auth::user()->is_parent )
<table class=" table table-bordered table-striped table-hover table-sm">
<thead>
<tr>
<th width="6" class="text-center">
</th>
<th width="10" class="text-center">
{{ trans('student.fields.status') }}
</th>
<th class="text-center">
{{ trans('student.fields.student_category') }}
</th>
<th class="text-center">
{{ trans('student.fields.first_registration') }}
</th>
<th class="text-center">
{{ trans('student.fields.first_name') }}
</th>
<th class="text-center">
{{ trans('student.fields.last_name') }}
</th>
<th class="text-center">
{{ trans('student.fields.birth_date') }}
</th>
<th class="text-center">
{{ trans('cruds.student.fields.academic_session') }}
</th>
<th class="text-center">
{{ trans('student.fields.academic_formation') }}
</th>
<th class="text-center">
{{ trans('student.fields.academic_class') }}
</th>
<th class="text-center">
{{ trans('student.fields.registration_type') }}
</th>
<th class="text-center">
</th>
</tr>
</thead>
<tbody>
#foreach($students as $student)
<tr>
<td class="text-center">
</td>
<td class="text-center">
{{ $student->status->name ?? '' }}
</td>
<td class="text-center">
#foreach($student->student_categories as $key => $item)
<span class="label label-info label-many">{{ $item->name }}</span>
#endforeach
</td>
<td class="text-center">
<span style="display:none">{{ $student->first_registration ?? '' }}</span>
<input type="checkbox" disabled="disabled" {{ $student->first_registration ? 'checked' : '' }}>
</td>
<td class="text-center">
{{ $student->first_name ?? '' }}
</td>
<td class="text-center">
{{ $student->last_name ?? '' }}
</td>
<td class="text-center">
{{ $student->birth_date ?? '' }}
#if ( $student->birth_date )
<ul class="list-unstyled">
<li>
{{ trans('student.fields.age') }} : {{ $student->age ?? '' }} years
</li>
</ul>
#endif
</td>
<td class="text-center">
{{ $student->academic_session->name ?? '' }}
</td>
<td class="text-center">
{{ $student->academic_formation->code ?? '' }}
</td>
<td class="text-center">
{{ $student->academic_class->name ?? '' }}
</td>
<td class="text-center">
{{ $student->registration_type->name ?? '' }}
<ul>
#if ( $student->entry_date )
<li>
{{ trans('student.fields.entry_date') }} : {{ $student->entry_date ?? '' }}
</li>
#endif
#if ( $student->exit_date )
<li>
{{ trans('student.fields.entry_date') }} : {{ $student->exit_date ?? '' }}
</li>
#endif
</ul>
</td>
<td class="text-center">
<ul class="list-unstyled">
<li>
#can('student_show')
<a class="btn btn-xs btn-primary" href="{{ route('app.students.show', $student->id) }}">
{{ trans('view') }}
</a>
#endcan
</li>
<li>
#can('student_edit')
<a class="btn btn-xs btn-info" href="{{ route('app.students.edit', $student->id) }}">
{{ trans('edit') }}
</a>
#endcan
</li>
<li>
#can('student_delete')
<form action="{{ route('app.students.destroy', $student->id) }}" method="POST" onsubmit="return confirm('{{ trans('are You Sure') }}');" style="display: inline-block;">
<input type="hidden" name="_method" value="DELETE">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="submit" class="btn btn-xs btn-danger" value="{{ trans('delete') }}">
</form>
#endcan
</li>
</ul>
</td>
</tr>
#endforeach
</tbody>
</table>
#else
.........
#endif
When I logged in as admin, the index datatable is working fine, but when I logged in as a parent which as children listed, the children aren't showed.
What did I miss?

print the last 5 articles in the dashboard

I would like to know how to put a list of the last 5 items in the dashboard using backpack?
I made the table
<div class="table-responsive">
<table class="table table-hover m-0 table-actions-bar">
<thead>
<tr>
<th>
<div class="btn-group dropdown">
<button type="button" class="btn btn-light btn-xs dropdown-toggle waves-effect waves-light"
data-toggle="dropdown" aria-expanded="false"><i class="mdi mdi-chevron-down"></i></button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</th>
<th>Titolo Post</th>
<th>Data</th>
<th>Stato</th>
<th>Categria</th>
<th>Azione</th>
</tr>
</thead>
<tbody>
<tr>
<td>
</td>
<td>
<h5 class="m-0 font-weight-medium"></h5>
</td>
<td>
<i class="mdi mdi-map-marker text-primary"></i>
</td>
<td>
<i class="mdi mdi-clock-outline text-success"></i>
</td>
<td>
<i class="mdi mdi-currency-usd text-warning"></i>
</td>
<td>
<i class="mdi mdi-pencil"></i>
<i class="mdi mdi-close"></i>
</td>
</tr>
</tbody>
</table>
</div>
I made the table inside the jumbotron.blade.php then the function that prints you on screen the last 5 posts I put it here? within the dashboard method?
$recentPost : Article::orderBy('id', 'desc')>limit(5)->get()
any other solution?
This line will get you the last 5 articles.
$articles = Article::orderBy('id', 'desc')->limit(5)->get();
You need to pass it to the view. Ex:
return view('dashboard', ['articles' => $articles]);
And loop the articles on the blade file table. Ex:
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Author</th>
<th scope="col">Date</th>
</tr>
</thead>
<tbody>
#foreach($articles as $article)
<tr>
<th scope="row">{{ $article->id }}</th>
<td>{{ $article->title }}</td>
<td>{{ $article->author }}</td>
<td>{{ $article->created_at }}</td>
</tr>
#endforeach
</tbody>
</table>

Resources