Skip to content

Commit 1d5e0fa

Browse files
committed
add todoapp code change
1 parent 4e6b9b9 commit 1d5e0fa

File tree

5 files changed

+33
-8
lines changed

5 files changed

+33
-8
lines changed

app/Http/Controllers/TodoController.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,51 @@ public function store(Request $request)
5151
*/
5252
public function show(string $id)
5353
{
54-
//
54+
$todos=Todo::findorFail($id);
55+
// return view('todos.show',['todos'=>$todos]);
56+
if (!$todos) {
57+
return redirect()->route('todos.index')->with('error', 'Job not found.');
58+
}
59+
60+
return view('todos.show', compact('todos'));
61+
5562
}
5663

5764
/**
5865
* Show the form for editing the specified resource.
5966
*/
6067
public function edit(string $id)
6168
{
62-
//
69+
$todos = Todo::findorFail($id);
70+
return view('todos.edit',['todos'=>$todos]);
6371
}
6472

6573
/**
6674
* Update the specified resource in storage.
6775
*/
6876
public function update(Request $request, string $id)
6977
{
70-
//
78+
$request->validate([
79+
'username'=>'required|string|max:255',
80+
'title'=>'required|string|max:255',
81+
'description'=>'required|string',
82+
]);
83+
$todos= new todo();
84+
$todos->username=$request->input('username');
85+
$todos->title=$request->input('title');
86+
$todos->description=$request->input('description');
87+
$todos->save();
88+
return redirect(route('todos.index'));
89+
7190
}
7291

7392
/**
7493
* Remove the specified resource from storage.
7594
*/
7695
public function destroy(string $id)
7796
{
78-
//
97+
$todos = Todo::findorFail($id);
98+
$todos->delete($id);
99+
return redirect()->route('todos.index')->with('seccess','Delete successfully');
79100
}
80101
}

resources/views/edit.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
</h6>
2121
</div>
2222
<div class="card-body">
23-
<form action="" method="post" enctype="multipart/form-data">
23+
<form action="{{ route('todos.edit') }}" method="post" enctype="multipart/form-data">
2424
@csrf
2525
<div class="form-group">
2626
<label> User Name</label>

resources/views/index.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@
4343
<td>{{ Str::limit($todo->description, 50 ,'...') }}</td>
4444
<td>{{ $todo->created_at->format('Y,M,D') }}</td>
4545
<td>
46-
<a class="btn btn-primary btn-sm text-white">View</a>
47-
<a class="btn btn-success btn-sm text-white">Edit</a>
48-
<form action="" method="post" style="display:inline-block">
46+
<a class="btn btn-primary btn-sm text-white" href="">View</a>
47+
<a class="btn btn-success btn-sm text-white" href="{{ route('todos.edit',$todo->id) }}">Edit</a>
48+
<form action="{{ route('todos.destroy', $todo->id) }}" method="post" style="display:inline-block">
4949
@csrf
5050
@method('DELETE')
5151
<button type="submit" class="btn btn-danger btn-sm " onclick="return confirm('Are you sure?')">Delete</button>

resources/views/show.blade.php

Whitespace-only changes.

routes/web.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,8 @@
66
Route::get('/',[TodoController::class,'index'])->name('todos.index');
77
Route::get('/todos/create',[TodoController::class,'create'])->name('todos.create');
88
Route::post('/todos',[TodoController::class,'store'])->name('todos.store');
9+
Route::get('{id}',[TodoController::class,'show'])->name('todos.show');
10+
Route::get('{id}/edit',[TodoController::class,'edit'])->name('todos.edit');
11+
Route::put('{id}',[TodoController::class,'update'])->name('todos.update');
12+
Route::delete('{id}',[TodoController::class,'destroy'])->name('todos.destroy');
913

0 commit comments

Comments
 (0)