Skip to content

Commit 370340c

Browse files
committed
upload code
1 parent 1d5e0fa commit 370340c

File tree

7 files changed

+99
-32
lines changed

7 files changed

+99
-32
lines changed

app/Http/Controllers/TodoController.php

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class TodoController extends Controller
1414
public function index()
1515
{
1616
$todos = Todo::all();
17-
return view('index',compact('todos'));
17+
return view('todos.index',compact('todos'));
1818
}
1919

2020
/**
2121
* Show the form for creating a new resource.
2222
*/
2323
public function create()
2424
{
25-
return view('create');
25+
return view('todos.create');
2626
}
2727

2828
/**
@@ -34,11 +34,13 @@ public function store(Request $request)
3434
'username'=>'required|string|max:255',
3535
'title'=>'required|string|max:255',
3636
'description'=>'required|string',
37+
3738
]);
3839
$todos= new todo();
3940
$todos->username=$request->input('username');
4041
$todos->title=$request->input('title');
4142
$todos->description=$request->input('description');
43+
4244
$todos->save();
4345
return redirect(route('todos.index'));
4446

@@ -51,13 +53,13 @@ public function store(Request $request)
5153
*/
5254
public function show(string $id)
5355
{
54-
$todos=Todo::findorFail($id);
56+
$todo=Todo::findorFail($id);
5557
// return view('todos.show',['todos'=>$todos]);
56-
if (!$todos) {
58+
if (!$todo) {
5759
return redirect()->route('todos.index')->with('error', 'Job not found.');
5860
}
5961

60-
return view('todos.show', compact('todos'));
62+
return view('todos.show', compact('todo'));
6163

6264
}
6365

@@ -66,25 +68,36 @@ public function show(string $id)
6668
*/
6769
public function edit(string $id)
6870
{
69-
$todos = Todo::findorFail($id);
70-
return view('todos.edit',['todos'=>$todos]);
71+
$todo= Todo::findOrFail($id);
72+
73+
74+
if (!$todo) {
75+
return redirect()->route('todos.index')->with('error', 'Todo list not found.');
76+
}
77+
78+
return view('todos.edit', compact('todo'));
7179
}
7280

81+
7382
/**
7483
* Update the specified resource in storage.
7584
*/
7685
public function update(Request $request, string $id)
7786
{
78-
$request->validate([
87+
$todo= Todo::find($id);
88+
89+
if (!$todo) {
90+
return redirect()->route('todods.index');
91+
}
92+
93+
$validateDate= $request->validate([
7994
'username'=>'required|string|max:255',
8095
'title'=>'required|string|max:255',
8196
'description'=>'required|string',
8297
]);
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();
98+
$todo->update($validateDate);
99+
100+
88101
return redirect(route('todos.index'));
89102

90103
}

resources/views/show.blade.php

Whitespace-only changes.

resources/views/create.blade.php renamed to resources/views/todos/create.blade.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
<!-- Bootstrap CSS -->
1111
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
12-
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/Trumbowyg/2.27.3/ui/trumbowyg.min.css">
1312

1413
</head>
1514
<body>
@@ -37,11 +36,10 @@
3736
3837
<div class="form-group">
3938
<label>Description</label>
40-
<textarea name="description" id="description" cols="5" rows="5" placeholder="Enter Description" class="form-control">{{ old('description') }}</textarea>
39+
<textarea name="description" id="description" cols="5" rows="5" class="form-control">{{ old('description') }}</textarea>
4140
@include('includes.form_error_msg',['field'=>'description'])
4241
</div>
4342
44-
4543
<div class="form-group">
4644
<input type="submit" value="Craete" class="btn btn-success">
4745
<a href="{{ route('todos.index') }}" class="btn btn-danger">Cancel</a>
@@ -53,18 +51,17 @@
5351
5452
</div>
5553
56-
</body>
57-
</html>
54+
5855
<!-- Optional JavaScript -->
5956
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
6057
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
6158
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
6259
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
60+
<script src="https://cdn.ckeditor.com/4.25.0-lts/standard/ckeditor.js"></script>
6361
64-
<script src="https://cdnjs.cloudflare.com/ajax/libs/Trumbowyg/2.27.3/trumbowyg.min.js" integrity="sha512-YJgZG+6o3xSc0k5wv774GS+W1gx0vuSI/kr0E0UylL/Qg/noNspPtYwHPN9q6n59CTR/uhgXfjDXLTRI+uIryg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
6562
<script>
66-
$('.textarea').trumbowyg();
67-
</script>
63+
CKEDITOR.replace( 'description' );
64+
</script>
6865
6966
</body>
7067
</html>

resources/views/edit.blade.php renamed to resources/views/todos/edit.blade.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,29 @@
2020
</h6>
2121
</div>
2222
<div class="card-body">
23-
<form action="{{ route('todos.edit') }}" method="post" enctype="multipart/form-data">
23+
<form action="{{ route('todos.update',$todo->id) }}" method="post" enctype="multipart/form-data">
2424
@csrf
25+
@method('PUT')
2526
<div class="form-group">
2627
<label> User Name</label>
27-
<input type="text" name="username" placeholder="Enter User Name" class="form-control" value="{{old('username',$todos->username)}}">
28+
<input type="text" name="username" placeholder="Enter User Name" class="form-control" value="{{old('username',$todo->username)}}">
2829
@include('includes.form_error_msg',['field'=>'username'])
2930
</div>
3031
<div class="form-group">
3132
<label> Title</label>
32-
<input type="text" name="title" class="form-control" placeholder="Enter Title" value="{{old('title',$todos->title)}}">
33+
<input type="text" name="title" class="form-control" placeholder="Enter Title" value="{{old('title',$todo->title)}}">
3334
@include('includes.form_error_msg',['field'=>'title'])
3435
</div>
3536
3637
<div class="form-group">
3738
<label>Description</label>
38-
<textarea name="description" id="" cols="5" rows="5" placeholder="Enter Description" class="form-control">value="{{old('title',$todos->description)}}</textarea>
39+
<textarea name="description" id="" cols="5" rows="5" placeholder="Enter Description" class="form-control">{{old('description',$todo->description)}}</textarea>
3940
@include('includes.form_error_msg',['field'=>'description'])
4041
</div>
4142
4243
4344
<div class="form-group">
44-
<input type="submit" value="Craete" class="btn btn-success">
45+
<input type="submit" value="Update" class="btn btn-success">
4546
<a href="{{ route('todos.index') }}" class="btn btn-danger">Cancel</a>
4647
</div>
4748
</form>

resources/views/index.blade.php renamed to resources/views/todos/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
<tr>
4040
<td>{{ $loop->index+1 }}</td>
4141
<td>{{ $todo->username }}</td>
42-
<td>{{ $todo->title }}</td>
42+
<td>{{ Str::limit($todo->title,30, '...') }}</td>
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" href="">View</a>
46+
<a class="btn btn-primary btn-sm text-white" href="{{ route('todos.show',$todo->id) }}">View</a>
4747
<a class="btn btn-success btn-sm text-white" href="{{ route('todos.edit',$todo->id) }}">Edit</a>
4848
<form action="{{ route('todos.destroy', $todo->id) }}" method="post" style="display:inline-block">
4949
@csrf
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<title>Title</title>
5+
<!-- Required meta tags -->
6+
<meta charset="utf-8">
7+
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
8+
9+
<!-- Bootstrap CSS -->
10+
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
11+
</head>
12+
<body>
13+
<div class="container mt-3 py-5 "style="font-family:'Times New Roman', Times, serif;">
14+
{{-- <h1 class="h3 mb-4 text-gray-800">ToDo List Details</h1> --}}
15+
<div class="card mb-4">
16+
<div class="card-header py-3">
17+
<h6 class="m-0 font-weight-bold text-primary text-center text-gray-800">Todo List Details</h6>
18+
</div>
19+
<div class="card-body">
20+
<div class="table-responsive">
21+
{{-- @include('includes.flash_message') --}}
22+
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
23+
<tr>
24+
<th>User Name</th>
25+
<td>{{ $todo->username }}</td>
26+
</tr>
27+
<tr>
28+
<th>Title</th>
29+
<td>{{ $todo->title }}</td>
30+
</tr>
31+
<tr>
32+
<th>Description</th>
33+
<td>{{ $todo->description }}</td>
34+
</tr>
35+
36+
37+
<tr>
38+
<th>Created At</th>
39+
<td>{{ $todo->created_at->format('D M Y') }}</td>
40+
</tr>
41+
</table>
42+
<a href="{{ route('todos.index') }}" class="btn btn-primary">Back to List</a>
43+
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
49+
50+
<!-- Optional JavaScript -->
51+
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
52+
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
53+
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
54+
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
55+
</body>
56+
</html>

routes/web.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +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');
9+
Route::get('/todos/{id}',[TodoController::class,'show'])->name('todos.show');
10+
Route::get('/todos/{id}/edit', [TodoController::class, 'edit'])->name('todos.edit');
11+
Route::put('/todos/{id}',[TodoController::class,'update'])->name('todos.update');
12+
Route::delete('/todos/{id}',[TodoController::class,'destroy'])->name('todos.destroy');
1313

0 commit comments

Comments
 (0)