Mit der „destroy()“ Methode lässt sich mit Eloquent ein Eintrag aus der Datenbank-Tabelle löschen:
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use App\Models\Website;
class WebsitesController extends Controller
{
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
// destroy method returns true or false
$websiteSuccessfullyDestroyed = Website::destroy($id);
if($websiteSuccessfullyDestroyed) {
return redirect()->route('websites.index')->with('success', 'Website successfully deleted!');
} else {
return redirect()->route('websites.index')->with('error', 'Website could not be deleted!');
}
}
}