I am making CRUD operation in laravel 5.4. I am deleteing an image from database and storage. I did it, but it deletes image name from database only. And do not delete from storage folder.
And I am doing one more thing, If I click on delete button then one confirmation box should be display. If click yes, then delete otherwise not delete. BUt it is also not working.
My web.php is:
Route::resource('todo','todocontroller');
My todocontroller.php is:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\todo;
class todocontroller extends Controller
{
public function index()
{
$todos = todo::paginate('3');
return view('todo.home',compact('todos'));
}
public function destroy($id)
{
$todos = todo::find($id);
if(\File::exists(public_path('public/storage/images/'.$todos->image))){
\File::delete(public_path('public/storage/images/'.$todos->image));
}
$todos->delete();
session()->flash('message','Deleted Successful');
return redirect('todo');
}
}
My home.blade.php is:
@extends('layout.app')
@section('body')
<br>
@if(session()->has('message'))
@endif
<div class="col-lg-4 col-lg-offset-4"><a href="todo/create" class="btn btn-info">Add new</a>
<h1>Todo Lists</h1>
<ul class="list-group">
@foreach($todos as $todo)
<li class="list-group-item d-flex justify-content-between align-items-center">
<span><img src="" style="height: 100px;width: 100px;"></span>
<a href="todo/"></a>
<span></span>
<span><a href="todo/">Edit</a></span>
<span>
<form class="delete" action="todo/" method="POST">
<button type="submit">Delete</button>
</form>
</span>
</li>
@endforeach
</ul>
</div>
<script>
$(".delete").on("submit", function(){
return confirm("Do you want to delete this item?");
});
</script>
@endsection
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2QwQ7cK
via IFTTT
Aucun commentaire:
Enregistrer un commentaire