20 May, 2022
19 May, 2022
404 Not found in Laravel when I try to make edit and update
Programing Coderfunda
May 19, 2022
Laravel, php
No comments
I already pass the id from the href anchor in list page, and still doesn't work. So maybe there is something wrong in controller or route but I'm not seeing it.
Controller
On the controller, I already add the edit and update function, I'm using Resource Controller Laravel-9
public function employee_edit($id)
{
if(Auth::check()){
$empl = employee::findOrFail($id);
return view('edit');
}else{
return redirect('login');
}
}
public function employee_update(Request $request, $id)
{
$input = $request->all();
$employee = employee::find($id);
$employee->update($input);
return redirect('employee');
}
Routes
In web route, I use put method in update route
Route::get('/employee/{$id}/edit', [EmployeeController::class,'employee_edit'])->name('employee.edit');
Route::put('/employee/{$id}/edit', [EmployeeController::class,'employee_update'])->name('employee.update');
Listemployee
This is the list page, as you can see in Edit anchor I already pass the id
@extends('layout.app')
@section('content')
<div class="card">
<div class="card-header">
<a href=""><button class="btn btn-primary position-absolute end-0 ">create new employee</button></a>
<h2>listEmployee</h2>
</div>
<div class="card-body">
<table class="table table-bordered border-dark mt-2 text-center">
<thead class="table table-dark">
<tr>
<th>#</th>
<th>Name</th>
<th>Age</th>
<th>Id employee</th>
</tr>
</thead>
<tbody>
@foreach ($employee as $item)
<tr>
<td>{{ $loop->iteration }}</td>
<td>{{ $item->name }}</td>
<td>{{ $item->age }}</td>
<td>{{ $item->id_employee }}<a href="{{ route('employee.edit',$item->id_employee) }}"><button class="btn btn-primary">Edit</button></a></td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
@endsection
Editemployee
@extends('layout.app')
@section('content')
<div class="card">
<div class="card-header">
<center><h2>EDIT EMPLOYEE</h2></center>
</div>
<div class="card-body">
<form class="form" action="{{ route('employee.edit',$empl->id_employee) }}" method="POST">
@method('put')
{{ csrf_field() }}
<label for="name">Name</label>
<input type="text" name="name" id="name" value="{{ $empl->name }}" class="form-control">
<label for="age">Age</label>
<input type="number" id="age" name="age" value="{{ $empl->age }}" class="form-control">
<center><button class="btn btn-primary mt-2">SUBMIT</button></center>
</form>
</div>
</div>
@endsectionLaravel 9 Localization got error Missing parameter: id when cast parameter
Programing Coderfunda
May 19, 2022
Laravel, php
No comments
Making ViewMenuComposer
Programing Coderfunda
May 19, 2022
Laravel, php
No comments
I would like to make a ViewMenuComposer that fills my menu from a global array. As I was creating my Livewire components, I would like to register them in an array to automatically populate a side menu.
What is the best practice for me to do this? For each route registered in routes/web.php would I populate this array or would I be able to define it in my Livewire components? I believe that a component code is not read if it is not being accessed, right?
I wouldn't want to leave my component/controller to record what I'm developing in some file.
Thanks.