I'm thinking how can I loop my records through textfield if the user hit the Edit button. I have search blade template where the list of records has put in the table data.
search.blade.php
<table class = "table">
<br>
<thead>
<tr>
<th>ID</th>
<th>Firstname</th>
<th>Lastname</th>
<th>Middlename</th>
<th>Email</th>
<th>Username</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
@foreach ($data as $row)
<tr class = "success">
<td>{{ $row->id }}</td>
<td>{{ $row->first_name }}</td>
<td>{{ $row->last_name }}</td>
<td>{{ $row->middle_name }}</td>
<td>{{ $row->email }}</td>
<td>{{ $row->username }}</td>
<td>
<a href = "{{ route ('account.edit', $row->id) }}"><button type = "submit" class = "btn btn-warning">Edit</button></a>
<a href = "#"><button type = "submit" class = "btn btn-danger">Archive</button></a>
</td>
</tr>
@endforeach
</tbody>
I loop also the id
of the Users table in my account.edit
view so it will know which id is selected.
Routes:
//READ
Route::get('/search',
[
'uses' => '\App\Http\Controllers\AccountController@getEmployee',
'as' => 'account.search',
]);
//EDIT
Route::get('/edit/{id}',
[
'uses' => '\App\Http\Controllers\AccountController@editEmployee',
'as' => 'account.edit',
]);
Controller:
//READ
public function getEmployee()
{
$result = DB::table('users')->get();
return view ('account.search')->with('data', $result);
}
//EDIT
public function editEmployee($id)
{
$result = User::find($id);
return view ('account.edit')->with('data', $result);
}
This part where I stuck still do not have a idea where I'm gonna loop each table attributes in my edit blade template unfortunately it gives me a error.
Missing required parameters for [Route: account.edit] [URI: edit/{id}]. (View: C:\Users\JohnFrancis\LaravelFrancisesources\views\account\edit.blade.php)
<form class = "form-vertical" role = "form" method = "post" action = "{{ route ('account.edit') }}">
<h3>Edit Employee</h3>
<hr>
<div class = "form-group">
<label for = "email" class = "control-label">Email Address</label>
<input type = "text" name = "email" class = "form-control" value = "{{ $result->email }}">
</div>
<div class = "form-group">
<label for = "username" class = "control-label">Username</label>
<input type = "text" name = "username" class = "form-control" value = "{{ $result->username }}">
</div>
<div class = "form-group">
<button type = "submit" class = "btn btn-success">Save</button>
</div>
<input type = "hidden" name = "id" value = "{{ $result->id }}">
<input type = "hidden" name = "_token" value = "{{ Session::token() }}">
</form>