Похожие презентации:
Редактирование и удаление
1.
Редактирование иудаление
2.
@foreach ($notes as $note)<div class="card">
<h2>{{ $note->title }} от {{ $note->user->login }}</h2>
<p> {{ $note->text }}</p>
<p> {{ $note->date }}</p>
<form method="post" action="{{ route('deleteNote', ['note'=>$note] )}}">
@csrf
@method('delete')
<button type="submit" class="btn btn-danger">Удалить</button>
</form>
<!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#editNote{{ $note->id }}">
Редактировать запись
</button>
</div>
Блэйд
<!-- Modal -->
<div class="modal fade" id="editNote{{ $note->id }}" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="exampleModalLabel">Запись #{{ $note->id }}</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<form method="post" action="{{ route('editNote', ['note'=>$note] )}}">
@csrf
@method('PUT')
<input type="text" name="title" value="{{ $note->title }}" placeholder="Название...">
<input type="text" name="text" value="{{ $note->text }}" placeholder="Текст...">
<button type="submit" class="btn btn-primary">Сохранить</button>
</form>
</div>
</div>
</div>
</div>
3.
Контроллерpublic function deleteNote(Note $note){
$note->delete();
return back()->with("ok","Запись удалена");
}
public function editNote(Request $request, Note $note){
$note->title = $request->title;
$note->text = $request->text;
$note->update();
return back()->with("ok","Запись изменена");
}
4.
РутыRoute::delete('deleteNote/{note}', [NoteController::class, 'deleteNote'])->name('deleteNote');
Route::put('editNote/{note}', [NoteController::class, 'editNote'])->name('editNote');
5.
Пагинацияpublic function profile(){
$user = Auth::user();
$query = Note::query();
$notes = $query->where("user_id", $user->id)->paginate(5);
return view("profile", compact("user", "notes"));
}
{{ $notes->links('pagination::bootstrap-5') }}
6.
Домашнее задание1. Добавить возможность удалять и редактировать записи
2. Добавить пагинацию в 10 записей
3. Создать страницу “Теги”. Добавить возможность создавать,
редактировать и удалять теги.