Blade Engine Elements Render Sorting - php

I have this code :
<div class="table-responsive">
<table class="table table-condensed table-hover">
<tr>
<th>#</th>
<th>Name</th>
<th>username</th>
<th>Email</th>
<th>Rank</th>
<th>Join</th>
</tr>
#if($count)
#foreach($users as $i => $user)
<tr>
<td>{{ $i+1 }}</td>
<td>{{ $user->first_name }} {{ $user->last_name }}</td>
<td>{{ $user->username }}</td>
<td>{{ $user->email }}</td>
<td>
#if($user->rank == 0)
Admin
#else
User
#endif
</td>
<td>{{ $user->created_at }}</td>
{{ Form::hidden('id', $user->id,['class'=>'id']) }}
{{ Form::hidden('username', $user->username,['class'=>'username']) }}
<td><button id="submit" type="button" class="btn btn-danger" data-toggle="modal" data-target="#deleteModal">
Delete
</button></td>
</tr>
#endforeach
#else
<div class="alert alert-success" style="text-align:center">
There is no users in the Site
</div>
#endif
which used Blade Template engine, but in case that's count is false the alert div appears before Heading of table
How can this problem be fixed ?

I may be missing something here, the code above seems incomplete (table is not closing). But why not move your alert outside of the other if so you can place it where you need it:
#if(!$count)
<div class="alert alert-success" style="text-align:center">
There is no users in the Site
</div>
#endif

Related

The delete button never return or redirect (never responds)

First I had to click on a delete button but it returns nothing, I don't know why.
It must go to a delete function on invoicesController.php file and do whatever I want to do.
This is my invoices controller to return all invoices:
public function index()
{
$invoice = invoices::all();
return view('invoices.invoice')->with('in', $invoice);
}
And this is my blade table:
<table id="example" class="table key-buttons text-md-nowrap">
<thead>
<tr>
<th class="border-bottom-0">#</th>
<th class="border-bottom-0">رقم الفاتورة</th>
<th class="border-bottom-0">تاريخ الفاتورة</th>
<th class="border-bottom-0">تاريخ الاستحقاق</th>
<th class="border-bottom-0">المنتج</th>
<th class="border-bottom-0">القسم</th>
<th class="border-bottom-0">الخصم</th>
<th class="border-bottom-0">نسبة الضريبة</th>
<th class="border-bottom-0">قيمة الضريبة</th>
<th class="border-bottom-0">الاجمالي</th>
<th class="border-bottom-0">الحالة</th>
<th class="border-bottom-0">ملاحظات</th>
<th class="border-bottom-0">العمليات</th>
<th></th>
</tr>
</thead>
<tbody>
#php
$a=0;
#endphp
#foreach ($in as $i)
<tr>
<td>{{ $a++ }}</td>
<td>{{ $i->invoice_number }}</td>
<td>{{ $i->invoice_date }}</td>
<td>{{ $i->due_date }}</td>
<td>{{ $i->product }}</td>
<td>
{{ $i->section->section_name }}
</td>
<td>{{ $i->discount }}</td>
<td>{{ $i->rate_vat }}</td>
<td>{{ $i->value_vat }}</td>
<td>{{ $i->total }}</td>
<td>
#if ($i->value_status == 1)
<span class="text-status">{{ $i->status }}</span>
#elseif($i->value_status == 2)
<span class="text-danger">{{ $i->status }}</span>
#else
<span class="text-warning">{{ $i->status }}</span>
#endif
</td>
<td>{{ $i->note }}</td>
<td>
edit
this is the issue
<form action="{{ route('in.delete' , $i->id) }}" method="get">
#csrf
<input type="hidden" value="{{ $i->id }}">
<button type="button">delete</button>
</form>
</td>
</tr>
#endforeach
</tbody>
</table>
Here is my delete function from invoicesController:
public function delete(Request $request)
{
dd($request);
}
My web.php:
Route::post('in/{id}', [App\Http\Controllers\InvoicesController::class, 'delete'])
->name('in.delete');
First of all, change your web.php route from post to delete:
Route::delete('in/{id}', [App\Http\Controllers\InvoicesController::class, 'delete'])
->name('in.delete');
Second, change your form method from get to POST:
<form action="{{ route('in.delete', $i->id) }}" method="POST">
And lastly, after that exact <form> tag and before #csrf, add a new blade directive that will "simulate" you are sending this form as DELETE:
<form action="{{ route('in.delete', $i->id) }}" method="POST">
#method('DELETE')
#csrf
You can read more about #method here.

data-bs-target with id not working in laravel

I have a modal pop out when pressing a button. Problem is, how do pass the value to the modal?
My table as shown in figure below. As you can see each row have different id. I wanted to get the id of a particular row after pressed the button.
The problem is how to display data in to bootstrap modal according to id. Thanks in advance.
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>ردیف</th>
<th>مقطع تحصیلی</th>
<th>رشته تحصیلی</th>
<th>تاریخ اخذ مدرک</th>
<th>جزییات بیشتر</th>
</tr>
</thead>
<tbody>
#foreach($user->educationals as $educational)
<tr>
<td class="fw-normal">{{ $educational->id }}</td>
<td class="fw-normal">{{ $educational->grade }}</td>
<td class="fw-normal">{{ $educational->major }}</td>
<td class="fw-normal">{{ $educational->end }}</td>
<td><a class="btn btn-link" data-bs-toggle="modal" data-bs-target="#educationals{{ $educational->id }}">جزییات بیشتر</a></td>
</tr>
#endforeach
</tbody>
</table>
</div>
#if(isset($educational))
<div class="modal fade" id="educationals{{ $educational->id }}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="educationals{{ $educational->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="educationals{{ $educational->id }}">درخواست</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<th>مقطع تحصیلی</th>
<td>{{ $educational->grade }}</td>
</tr>
<tr>
<th>رشته تحصيلي</th>
<td>{{ $educational->major }}</td>
</tr>
<tr>
<th>معدل</th>
<td>{{ $educational->avg }}</td>
</tr>
<tr>
<th>تاريخ شروع</th>
<td>{{ $educational->start }}</td>
</tr>
<tr>
<th>تاريخ اخذ مدرك</th>
<td>{{ $educational->end }}</td>
</tr>
<tr>
<th>موسسه دريافت اخذ مدرك</th>
<td>{{ $educational->docPlaceName }}</td>
</tr>
<tr>
<th>عنوان پايان نامه / رساله</th>
<td>{{ $educational->thesisTitle }}</td>
</tr>
<tr>
<th>مدارك</th>
<td>{{ $educational->upload_doc }}</td>
</tr>
<tr>
<th>کشور محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCountry }}</td>
</tr>
<tr>
<th>شهر محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCity }}</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">اوکی</button>
</div>
</div>
</div>
</div>
#else
<div class="alert alert-warning text-center" role="alert">
اطلاعاتی وجود ندارد.
</div>
#endif
You have many options but I suggest you to use javascript in any form you prefer. But if you don't want to use javascript, you should make model for each of table rows.
#foreach($user->educationals as $educational)
<div class="modal fade" id="educationals{{ $educational->id }}" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="educationals{{ $educational->id }}" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="educationals{{ $educational->id }}">درخواست</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<table class="table">
<tr>
<th>مقطع تحصیلی</th>
<td>{{ $educational->grade }}</td>
</tr>
<tr>
<th>رشته تحصيلي</th>
<td>{{ $educational->major }}</td>
</tr>
<tr>
<th>معدل</th>
<td>{{ $educational->avg }}</td>
</tr>
<tr>
<th>تاريخ شروع</th>
<td>{{ $educational->start }}</td>
</tr>
<tr>
<th>تاريخ اخذ مدرك</th>
<td>{{ $educational->end }}</td>
</tr>
<tr>
<th>موسسه دريافت اخذ مدرك</th>
<td>{{ $educational->docPlaceName }}</td>
</tr>
<tr>
<th>عنوان پايان نامه / رساله</th>
<td>{{ $educational->thesisTitle }}</td>
</tr>
<tr>
<th>مدارك</th>
<td>{{ $educational->upload_doc }}</td>
</tr>
<tr>
<th>کشور محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCountry }}</td>
</tr>
<tr>
<th>شهر محل دريافت مدرك</th>
<td>{{ $educational->docPlaceCity }}</td>
</tr>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal">اوکی</button>
</div>
</div>
</div>
</div>
#endforeach

Undefined Variable on fetching data in view

I'm trying to print values in from database in table. However the error shows undefined variable outlets in app.blade.php. I'm a beginner in laravel I've copied the function from index.blade.php where it is working. Any help will be highly appreciative.
App.blade.php:
<div class="col-md-12">
<div class="card">
<div class="card-header">
<form method="GET" action="" accept-charset="UTF-8" class="form-inline">
<input type="submit" value="{{ __('outlet.search') }}" class="btn btn-secondary">
{{ __('app.reset') }}
</form>
</div>
<table class="table table-sm table-responsive-sm">
<thead>
<tr>
<th class="text-center">{{ __('app.table_no') }}</th>
<th>{{ __('outlet.name') }}</th>
<th class="text-center">{{ __('app.action') }}</th>
</tr>
</thead>
<tbody>
#foreach($outlets as $key => $outlet)
<tr>
<td class="text-center">{{ $outlets->firstItem() + $key }}</td>
<td>{!! $outlet->name_link !!}</td>
<td>{{ $outlet->address }}</td>
<td>{{ $outlet->latitude }}</td>
<td>{{ $outlet->longitude }}</td>
<td class="text-center">
{{ __('app.show') }}
</td>
</tr>
#endforeach
</tbody>
</table>
<div class="card-body">{{ $outlets->appends(Request::except('page'))->render() }}</div>
OutletController.php
public function index()
{
$this->authorize('manage_outlet');
$outletQuery = Outlet::query();
$outletQuery->where('name', 'like', '%'.request('q').'%');
$outlets = $outletQuery->paginate(25);
return view('outlets.index', compact('outlets'));
}
public function app()
{
$outlets = "this is outlet";
return view('outlets.app', compact('outlets'));
}
Error:
ErrorException (E_ERROR)
Undefined variable: outlets (View: /home/converse/laravel_leaflet_1/resources/views/layouts/app.blade.php) (View: /home/converse/laravel_leaflet_1/resources/views/layouts/app.blade.php)

A non-numeric value encountered in Laravel script

In my Laravel script on a page this error appears:
"A non-numeric value encountered (View: /home/grammer/public_html/test/core/resources/views/admin/apiServices.blade.php)"
for this line
<td>{{ $key+1 }}</td>
my page codes:
#extends('admin.layouts.master')
#section('page_icon', 'fa fa-suitcase')
#section('page_name', 'API Services')
#section('body')
<div class="row">
<div class="col-md-12">
<div class="tile">
<h3 class="tile-title">API Services List</h3>
<table class="table table-hover">
<thead>
<tr>
<th>Serial</th>
<th>Service ID</th>
<th>Name</th>
<th>Category</th>
<th>Price</th>
<th>Min</th>
<th>Max</th>
</tr>
</thead>
<tbody>
#foreach($items as $key => $item)
<tr>
<td>{{ $key+1 }}</td>
<td>{{ isset($item->service->id) ? $item->service->id : $item->service}}</td>
<td>{{ $item->name }}</td>
<td>{{ $item->category }}</td>
<td>{{ isset($item->rate) ? $item->rate : $item->price_per_k }} $</td>
<td>{{ $item->min }}</td>
<td>{{ $item->max }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
#endsection
Just add this :
<td>{{ (int) $key + 1 }}</td>
or Add this:
$key = (int) $key; // GET NUMBER FROM VARIABLE

Searching in db using Laravel 4.2

I want to search and display specific data from db and the method that I have made is not retrieving data from database, if i print it just gives a empty array.
My code is as follow:
Controller:
public function search() {
$search = Input::get('search');
if($search){
$query = DB::table('volunteer');
$results = $query ->where('bloodt', 'LIKE', $search) ->get();
//print_r($results); exit;
return View::make('search')->with("volunteer",$results);
}
}
View:
{{Form::open(array('method'=>'POST'))}}
<div class="pull-left col-xs-6 col-xs-offset-0">
{{Form::text('search','',array('placeholder'=>'Search by blood type/zip code/address....','class'=>'form-control','required autofocus'))}}
</div>
<input type="submit" name="search" value="Search" class="btn btn-primary">
<br><br>
{{Form::close()}}
<?php if (isset($results)) { ?>
#foreach($volunteer as $results)
<table class="table table-bordered" style="width: 100%; background-color: lightsteelblue">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>IC/Passport no.</th>
<th>Blood Type</th>
<th>Address</th>
<th>Zip Code</th>
<th>e-mail</th>
<th>Phone no.</th>
<th>Status</th>
</tr>
<tr>
<td>{{ $results->fname }}</td>
<td>{{ $results->lname }}</td>
<td>{{ $results->ic }}</td>
<td>{{ $results->bloodt }}</td>
<td>{{ $results->address }}</td>
<td>{{ $results->zipcode }}</td>
<td>{{ $results->email }}</td>
<td>{{ $results->phone }}</td>
<td>
<div class="btn-group" role="group">
<button class="btn btn-default dropdown-toggle" data-toggle="dropdown">
{{ $results->status }}
<span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li>Eligible</li>
<li>Not Eligible</li>
</ul>
</div>
</td>
</tr>
</table>
#endforeach
<?php;
} ?>
Route:
Route::post('search', 'HomeController#search');

Categories