i want to show image gallery at user page
this my code from ImageUserController
function list(){
$employees['img_user'] = ImageUser::where('user_id', Auth::user()->id)->get();
return view('ukm.index', $employees);
}
and this my code from UserContoller
public function list()
{
$employees = ImageUser::all();
$ukm = Ukm::all();
return view('/ukm/index', compact( 'employees', 'ukm'));
}
this my route
Route::get('/ukm/index', 'ImageUserController#list');
and this my code at ukm/index.blade.php
table class="table table-stripped table-bordered">
<thead class="thead-dark">
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th scope="col">Image</th>
<th scope="col">Edit</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
#foreach ($employees as $employee)
<tr>
<th scope="row">{{ $employee->id }}</th>
<td>{{ $employee->name }}</td>
<td>{{ $employee->description }}</td>
<td><img src="{{ asset('uploads/employee/' . $employee->image) }}" width="150px;" height="100px;" alt="Image"></td>
<td>Edit</td>
<td>Delete</td>
</tr>
#endforeach
</tbody>
</table>
i'm getting this error : Undefined variable: employees
You aren't passing the array to the view actually
return view('ukm.index')->with('employees', $employees);
In your ImageUserController list() method,
function list(){
$employees = ImageUser::where('user_id', Auth::user()->id)->get();
return view('ukm.index', compact('employees'));
}
Related
I tried to display all menus from the db in table form however i got an error saying that "undefined variable:menus(0)"
dashboard_index.blade.php
<div class= "menu-content">
<table class="table table-hover table-bordered">
<thead>
<tr>
<th scope="col"></th>
<th scope="col">Category Code</th>
<th scope="col">Menu Title</th>
<th scope="col">Menu Price</th>
</tr>
</thead>
<tbody>
#foreach ($menus as $menu)
<tr>
<td>{{ $menu->id }}</td>
<td>{{ $menu->category_code }}</td>
<td>{{ $menu->menu_title }}</td>
<td>RM{{ $menu->menu_price }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
web.php
Route::get('/dashboard', 'AdminMenuController#index');
AdminMenuController.php
public function index()
{
$menus = \App\Menu::all();
return view('admin.dashboard_index',
[
'menus'=>$menus,
]);
}
You have a syntax error in $menu = \App\Menu::all()
it should be $menus = \App\Menu::all()
Here is the web page:
Update data and ID is showing while other data such as customer name, phone, etc are not showing.
CustomersController.php
public function index()
{
$customers = Customer::all();
return view('customers.index', ['customers' => $customers]);
}
index.blade.php
#extends('layouts.app')
#section('content')
<h1>Customers</h1>
#if(count($customers)>0)
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Updated on</th>
</tr>
</thead>
#foreach($customers as $customer)
<tbody>
<tr>
<th scope="row">{{$customer->id}}</th>
<td>{{$customer->name}}</td>
<td>{{$customer->email}}</td>
<td>{{$customer->phone}}</td>
<td>{{$customer->add}}</td>
<td>{{$customer->updated_at}}</td>
</tr>
#endforeach
#else
#endif
#endsection
You didn't close <table> and <tbody>, and you placed <tbody> inside the loop (it should only appear once)
Try this:
#extends('layouts.app')
#section('content')
<h1>Customers</h1>
#if(count($customers)>0)
<table class="table">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Updated on</th>
</tr>
</thead>
<tbody>
#foreach($customers as $customer)
<tr>
<td>{{$customer->id}}</td>
<td>{{$customer->name}}</td>
<td>{{$customer->email}}</td>
<td>{{$customer->phone}}</td>
<td>{{$customer->add}}</td>
<td>{{$customer->updated_at}}</td>
</tr>
#endforeach
</tbody>
</table>
#else
#endif
#endsection
You didn't close your table tag and <tbody> tag and <tbody> opening tag should be start before foreach loop.
I'm creating a index.blade.php in view/back/client to list the clients.but I'm having this error.
Undefined variable: clients (View:
C:\wamp\www\myLSF\resources\views\back\clients\index.blade.php)
here is my index.blade.php
<table id="example1" class="table table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>First Name </th>
<th>Last Name</th>
<th>Address</th>
<th>Postal Code</th>
<th>City</th>
<th>Province</th>
<th>Phone</th>
</tr>
</thead>
<tbody>
#foreach($clients as $client)
<tr>
<td>{{ $client->id }} </td>
<td>{{ $client->firstname }}</td>
<td>{{ $client->lastname }}</td>
<td>{{ $client->address }}</td>
<td>{{ $client->postalcode }}</td>
<td>{{ $client->city }}</td>
<td>{{ $client->province }}</td>
<td>{{ $client->phoneno }}</td>
</tr>
#endforeach
</tbody>
<tfoot>
<tr>
<th>First Name </th>
<th>Last Name</th>
<th>Address</th>
<th>Postal Code</th>
<th>City</th>
<th>Province</th>
<th>Phone</th>
</tr>
</tfoot>
</table>
here is my clientcontroller.php
class clientController extends Controller
{
public function list()
{
$clients = client::get();
return view('/back/clients/index', compact('clients'));
}
}
here is my client.php model
class client extends Model
{
use Notifiable;
#var
protected $table='clients';
protected $fillable=
['firstname','lastname','address','postalcode',
'city','province','phoneno'];
}
here i set the route for this in web.php
Route::name('clients')->get('clients', 'clientController#list');
You need to import your client model into the clientController.php file.
To do this, add use App\client at the top, like so:
use App\client;
class clientController extends Controller
{
public function list()
{
$clients = client::get();
return view('/back/clients/index', compact('clients'));
}
}
I'm trying to get the count of different models and list them by company.
I have a collection of different models.
public function listAllRequets()
{
$requests = collect();
$terms = Termination::with('user.company')->where('default_status', 2)->get();
$deacs = LoaDeactivation::with('user.company')->where('manager_status', 2)->get();
$reacs = LoaReactivation::with('user.company')->where('manager_status', 2)->get();
// Use push() to collect them all in one collection
foreach ($terms as $term)
$requests->push($term);
foreach ($deacs as $deac)
$requests->push($deac);
foreach ($reacs as $reac)
$requests->push($reac);
return $requests;
}
In my index function I'm adding them to $requests.
To get the list of companies I'm grouping them using the groupBy() method.
public function index()
{
$requests = $this->listAllRequets();
$requestCompanies = $requests->groupBy(function($requests) {
return $requests->user->company->company_acronym;
});
In my view I have this:
<table class="table table-sm">
<thead class="thead-light">
<tr>
<th>Company</th>
<th class="text-center">Terms</th>
<th class="text-center">Deacs</th>
<th class="text-center">Reacs</th>
</tr>
</thead>
<tbody>
#foreach ($requestCompanies as $company => $requests)
<tr>
<td class="pt-3"><strong>{{ $company }}</strong></td>
#foreach ($requests as $request)
<td class="text-center">{{ $request-> }}</td>
#endforeach
</tr>
#endforeach
</tbody>
</table>
I need a way to get the count of each model by company.
My companies list out as expected but I'm not sure how to get the correct model count.
If you have relationships among your company and each request model (Termination, LoaDeactivation, LoaReactivation), wouldn't be easier to do that with a query at database level?
That seems a nice use case for with count method that eloquent provides:
Assuming the relations in the company model are called terminations, deactivations and reactivations, you could do:
public function index()
{
$companies = Company::withCount('terminations','deactivations','reactivations')->get();
// here pass $companies array to your view
}
Then in your view you can access the count for each type on each company:
<table class="table table-sm">
<thead class="thead-light">
<tr>
<th>Company</th>
<th class="text-center">Terms</th>
<th class="text-center">Deacs</th>
<th class="text-center">Reacs</th>
</tr>
</thead>
<tbody>
#foreach ($companies as $company)
<tr>
<td class="pt-3"><strong>{{ $company->name }}</strong></td>
<td class="text-center">{{ $company->terminations_count }}</td>
<td class="text-center">{{ $company->deactivations_count }}</td>
<td class="text-center">{{ $company->reactivations_count }}</td>
</tr>
#endforeach
</tbody>
</table>
Trying to make one html table where is showing what login users choose.
One login auth users and one form data.
Here data is showing on page but scramled in table.
Homedata is showing twice.
Here is my index page where im trying to do:
<table class="table" id="users-info">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First Name</th>
<th scope="col">Last Name</th>
<th scope="col">Naional Number</th>
<th scope="col">Device</th>
<th scope="col">Reimbursment</th>
<th scope="col">Warranty</th>
</tr>
</thead>
<tbody>
#if(count($users) > 0)
#foreach($users as $user)
<tr>
<th scope="row">{{ $user->id }}</th>
<td>{{ $user->firstname }}</td>
<td>{{ $user->lastname }}</td>
<td>{{ $user->phone }}
#foreach($homedata as $homedatas)
<td>{{$homedatas->device}}</td>
<td>{{$homedatas->reimburse_Pension}}</td>
<td>{{$homedatas->bonus_remainder}}</td>
#endforeach
</td>
</tr>
#endforeach
#endif
</tbody>
</table>
Please help.
if there is another way please feel free suggest.
Hey everyone who share the same problem.
I add in second foreach ->slice(0, 1) and that foreach just going once, that automaticaly means no duplicate data :)