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)
Related
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.
I'm beginner in laravel, when I put stats table in blade I got this warning
Attempt to read property "name" on array (View: C:\xampp\htdocs\Testing\resources\views\product.blade.php)
This is Controller
public function index()
{
$response = Http::get('https://api.lazada.co.id/rest/products/get?filter=live&app_key=100132&sign_method=sha256×tamp=1612318435886&access_token=50000801006o5nrcA5192d1f9ag1FHQBUqffCEyCmrXDohvhzExSkczUnnxJ4y&sign=F31584775544970D59AB58EC4B1B77933BC2D32401E33C1D2D5095690C31627C');
$data = $response->json();
return view('product',compact ('data'));
}
This is view:
#extends('layout/main')
#section ('title', 'Testing Laravel')
#section ('container')
<div class="container">
<div class="row">
<div class="col-10">
<h1 class="mt-3">List Product</h1>
<table class="table">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Desc</th>
<th scope="col">Brand</th>
<th scope="col">Clothing Material</th>
<th scope="col">Leather Material</th>
</tr>
</thead>
<tbody>
#foreach($data as $datas)
<tr>
<th scope="row">1</th>
<td>{{ $datas->name }}</td>
<td>{{ $datas-description }}</td>
<td>{{ $datas->brand }}<td>
<td>{{ $datas->clothing_material }}</td>
<td>{{ $datas->leather_material }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
#endsection
According to the error message its clearly saying Attempt to read property (because you are trying to access like $data->name <--OBJECT) on array and your foreach variable is array. so you will need to access like key value pair.
Use like this in loop-
{{ $data['name'] }}
{{ $data['description'] }}
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
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
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');