Skip to content

Commit

Permalink
change all route to index route form todos route
Browse files Browse the repository at this point in the history
  • Loading branch information
slayer321 committed Oct 26, 2023
1 parent c0fce3f commit 9607a95
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 14 deletions.
10 changes: 5 additions & 5 deletions src/app/Http/Controllers/TodoController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ public function store(Request $request)

if ($validator->fails())
{
return redirect()->route('todos.index')->withErrors($validator);
return redirect()->route('index')->withErrors($validator);
}


Todo::create([
'title'=>$request->get('title')
]);

return redirect()->route('todos.index')->with('success', 'Inserted');
return redirect()->route('index')->with('success', 'Inserted');

}

Expand Down Expand Up @@ -81,7 +81,7 @@ public function update(Request $request, string $id)

if ($validator->fails())
{
return redirect()->route('todos.edit',['todo'=>$id])->withErrors($validator);
return redirect()->route('edit',['todo'=>$id])->withErrors($validator);
}


Expand All @@ -91,7 +91,7 @@ public function update(Request $request, string $id)
$todo->is_completed=$request->get('is_completed');
$todo->save();

return redirect()->route('todos.index')->with('success', 'Updated Todo');
return redirect()->route('index')->with('success', 'Updated Todo');
}

/**
Expand All @@ -101,6 +101,6 @@ public function destroy($id)
{
//
Todo::where('id',$id)->delete();
return redirect()->route('todos.index')->with('success', 'Deleted Todo');
return redirect()->route('index')->with('success', 'Deleted Todo');
}
}
2 changes: 1 addition & 1 deletion src/resources/views/edit-todo.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<h2>Edit Todo</h2>
</div>

<form method="POST" action="{{route('todos.update',['todo'=>$todo->id])}}">
<form method="POST" action="{{route('update',['id'=>$todo->id])}}">

@csrf

Expand Down
6 changes: 3 additions & 3 deletions src/resources/views/todo.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="text-center mt-5">
<h2>Add Todo</h2>

<form class="row g-3 justify-content-center" method="POST" action="{{route('todos.store')}}">
<form class="row g-3 justify-content-center" method="POST" action="/store">
@csrf
<div class="col-6">
<input type="text" class="form-control" name="title" placeholder="Title">
Expand Down Expand Up @@ -56,8 +56,8 @@
@endif
</td>
<td>
<a href="{{route('todos.edit',['todo'=>$todo->id])}}" class="btn btn-info">Edit</a>
<a href="{{route('todos.destroy',['todo'=>$todo->id])}}" class="btn btn-danger">Delete</a>
<a href="{{route('edit',['id'=>$todo->id])}}" class="btn btn-info">Edit</a>
<a href="{{route('destroy',['id'=>$todo->id])}}" class="btn btn-danger">Delete</a>
</td>
</tr>

Expand Down
18 changes: 13 additions & 5 deletions src/routes/web.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\TodoController;

/*
|--------------------------------------------------------------------------
Expand All @@ -13,11 +14,18 @@
|
*/

Route::get('/', function () {
return view('welcome');
});
// Route::get('/', function () {
// return view('welcome');
// });



Route::resource('todos', \App\Http\Controllers\TodoController::class);
Route::get('todos/{todo}', [\App\Http\Controllers\TodoController::class,'destroy'])->name('todos.destroy');
// Route::resource('/', \App\Http\Controllers\TodoController::class);
// Route::get('todos/{todo}', [\App\Http\Controllers\TodoController::class,'destroy'])->name('todos.destroy');

Route::get('/', [TodoController::class, 'index'])->name('index');
Route::get('/create', [TodoController::class, 'create']);
Route::post('/store', [TodoController::class, 'store'])->name('store');
Route::get('/edit/{id}', [TodoController::class, 'edit'])->name('edit');
Route::put('/update/{id}', [TodoController::class, 'update'])->name('update');
Route::get('/destroy/{id}', [TodoController::class, 'destroy'])->name('destroy');

0 comments on commit 9607a95

Please sign in to comment.