I have a table display and each row contains a button. With this button l have to pass the id to the controller where using this Admin can view user details one by one.
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<button type="submit" class="btn btn-
default" name="viewcv"> View</button> <br>
<br>
</td>
</tr>
#endforeach
</tbody>
</table>
Please check the code , hope it helps:
<table id="example2" class="table table-bordered table-hover" style="text-align: center">
<thead>
<tr>
<th>Applicant ID</th>
<th>Full name</th>
<th>Position applied</th>
<th>Date & time applied</th>
<th>View CV</th>
</tr>
</thead>
<tbody>
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>CV</td>
</tr>
#endforeach
</tbody>
</table>
Assuming you want to pass the field "id" or change it according to your requirement.
If you want to link to a show view, try something like this:
#foreach ($jobapplied as $row)
<tr>
<td>{{$row->app_id}}</td>
<td>{{$row->fullname}}</td>
<td>{{$row->position}}</td>
<td>{{$row->created_at}}</td>
<td>
<a href="{{action('JobController#show', $row->id)}}" class="btn btn-default">View</button>
</td>
</tr>
#endforeach
This will create a link to a view, where you can show the data.
In your controller JobController, you must create a function that receives the data:
public function show(Request $request, $id) {
...
}
Just pass the id of the record to controller function and get the details from database.
<td>
View <br>
</td>
Related
In this image this table is based on my databse "Employee" table. there is 2 part. 1st part is from "#" column to "employee type" column. 2nd part is "Leave Type" Column. This column infromation will come from "LeaveType" Table. No I want to create different type leavetype for 1 employee. It mean I want to create subrow for each parent row in this column. But I can't
here is my incomplete table code in blade file.
<table class="table table-bordered mb-0" id="myTable">
<thead class="bg-orange">
<tr class="text-light">
<th >#</th>
<th >Employee Name</th>
<th >Employee Id</th>
<th >Employee Type</th>
<th >Leave Type</th>
<th >Entitled</th>
<th >Used Leave</th>
<th >Balance</th>
</tr>
</thead>
<tbody>
#foreach($users as $user)
<tr>
<th scope="row">{{$loop->iteration}}</th>
<td>
{{$user->name}} <br>
#foreach($designations as $designation)
#if($designation->id === $user->designationId)
{{$designation->designationName}}
<br>
#endif
#endforeach
#foreach($departments as $department)
#if($department->id === $user->departmentId)
{{$department->departmentName}}
#endif
#endforeach
</td>
<td>{{$user->employeeId}}</td>
#foreach($designations as $designation)
#if($designation->id === $user->designationId)
<td>{{$designation->attendanceType}}</td>
<br>
#endif
#endforeach
<td>
</td>
</tr>
#endforeach
</tbody>
</table>
On my controller take data via foreach where the $upcoming->order_id is same I am checked by dd($notes) data is show but i can't get on my view php. before I am tried $note->get('amount') method it is also not working
public function index()
{ $upcomings = Booking_informations::Upcoming();
$notes = [];
foreach ($upcomings as $upcoming) {
$notes[] = Notes :: where('order_id',$upcoming->order_id)-> orderBy('id', 'ASC')->get();
};
return View('upcoming',compact('upcomings','notes',));
}
upcoming.blade.php
<table class="table table-bordered mb-0">
<tbody>
#foreach($notes as $note )
<tr>
<th scope="row">1</th>
<td>{{date('d-M-Y', strtotime($note->created_at))}}</td>
<td>{{$note->details}} </td>
<td>{{$note->amount}} </td>
</tr>
#endforeach
</tbody>
</table>
I have got answer while wrote below method have any more simple way for get results..
<table class="table table-bordered mb-0">
<thead>
<tr>
<th>#</th>
<th>Date</th>
<th>Content</th>
<th>Amount</th>
</tr>
</thead>
<tbody>
#foreach($notes as $note )
#foreach($note as $id )
<tr>
<td scope="row">1</td>
<td>{{$id->details}} </td>
<td>{{$id->amount}} </td>
</tr>
#endforeach
#endforeach
</tbody>
</table>
Try referencing $note instead of $notes in your foreach loop and see if that works.
I have also noticed that you have named your view file View.blade.php. Should this be upcoming.blade.php to match the name you have provided in the returned view? Just a thought.
Please help check the code to see where there is error as I am not a coder but just using the application from another developer
<div class="bs-example widget-shadow table-responsive" data-example-id="hoverable-table">
<table class="table table-hover">
<thead>
<tr>
<th>ID</th>
<th>Client name</th>
<th>Amount</th>
<th>Payment mode</th>
<th>Receiver's email</th>
<th>Status</th>
<th>Date created</th>
<th>Option</th>
</tr>
</thead>
<tbody>
#foreach($withdrawals as $deposit)
<tr>
<th scope="row">{{$deposit->id}}</th>
<td>{{$deposit->duser->name}}</td>
<td>{{$deposit->amount}}</td>
<td>{{$deposit->payment_mode}}</td>
<td>{{$deposit->duser->email}}</td>
<td>{{$deposit->status}}</td>
<td>{{$deposit->created_at}}</td>
<td> <a class="btn btn-default" href="{{ url('dashboard/pwithdrawal') }}/{{$deposit->id}}">Process</a></td>
</tr>
#endforeach
The problem is in {{$deposit->duser->name}} and {$deposit->duser->email}}. Every withdrawal must have a valid user ID. This user ID will be matched against user table and the name and email of that user will be showed in blade.
What is happening is this, one or more $deposit has invalid user ID. So, the blade is trying to search in the table to get the name and email. But it is not finding it. So essentially it is trying to get the name value of a null object and crashing the app.
You can try to check if the duser have a null value by using following code,
#foreach($withdrawals as $deposit)
#if(!is_null($deposit->duser))
<tr>
<th scope="row">{{$deposit->id}}</th>
<td>{{$deposit->duser->name}}</td>
<td>{{$deposit->amount}}</td>
<td>{{$deposit->payment_mode}}</td>
<td>{{$deposit->duser->email}}</td>
<td>{{$deposit->status}}</td>
<td>{{$deposit->created_at}}</td>
<td> <a class="btn btn-default" href="{{ url('dashboard/pwithdrawal') }}/{{$deposit->id}}">Process</a></td>
</tr>
#endif
#endforeach
My code is here if you want any other section of code, i will provide also that piece of code
<div class="panel-heading ">Organization Profile</div>
<table class="table table-striped">
<thead>
<tr>
<th>Attributes</th>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr>
<td>Org Name</td>
<td>{{$org->name}}</td>
</tr>
<tr>
<td>Owner Name</td>
<td>{{$org->owner}}</td>
</tr>
</tbody>
</table>
</div>
Trying to get property of non-object issue usually comes in Laravel when you are returning array but try using object in your blade file or not passing the correct object string at all.
I notice from comments that you are passing $orgs, not $org in the function.
public function create() {
return view('Admin.organizations.create',compact('orgs'));
}
Update your blade file like below:
<div class="panel-heading ">Organization Profile</div>
<table class="table table-striped">
<thead>
<tr>
<th>Attributes</th>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr>
<td>Org Name</td>
<td>{{$orgs->name}}</td>
</tr>
<tr>
<td>Owner Name</td>
<td>{{$orgs->owner}}</td>
</tr>
Considering all the comments, you should probably have something like this in your controller:
public function show($id)
{
$org = Organization::find($id);
// $data = ['org', $id];
return view('Admin.organizations.show')->with(compact('org'));
}
and this is your blade view:
<div class="panel-heading ">Organization Profile</div>
#if (empty($org))
<h1>Organization is empty</h1>
#else
<table class="table table-striped">
<thead>
<tr>
<th>Attributes</th>
<th>Values</th>
</tr>
</thead>
<tbody>
<tr>
<td>Org Name</td>
<td>{{$org->name}}</td>
</tr>
<tr>
<td>Owner Name</td>
<td>{{$org->owner}}</td>
</tr>
</tbody>
</table>
#endif
</div>
Of course not knowing what is in the Organization model would keep us from knowing whether owner and name exist as properties of the model.
Hello i am a laravel beginner , when i do foreach its shows double of all single items what should i do with it code and ss are below
Brower image
code
<div >
<h1 style="text-align: center">Lists of Outlets</h1>
#foreach($outlets as $outlet)
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
</tbody>
</table>
#endforeach
</div>
The issue is, you have put the entire table inside the loop, which is wrong. You have to only put the tr inside the loop.
Try this:
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
and one more thing, you are also using the static content inside the loop instead of using the loop variable value. So instead of:
<td>john#example.com</td>
it is something like:
<td>{{ $outlet['name'] }}</td> <!-- where name is the index in outlet array -->
#foreach should be inside <tbody> and instead of hard-coded content, you should be using $outlet variable to get firstname, lastname and Email:
<div>
<h1 style="text-align: center">Lists of Outlets</h1>
<table class="table table-striped">
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
<tbody>
#foreach($outlets as $outlet)
<tr>
<td>John</td>
<td>Doe</td>
<td>john#example.com</td>
</tr>
#endforeach
</tbody>
</table>
</div>