这里新增了laravel框架。我在这里调用我的资源控制器中的删除功能时遇到了相当大的问题。似乎不会删除选定的ID。感谢您的帮助提前。删除功能:Laravel 5
资源/视图/ bufashaccts/allAccounts.blade.php
@extends('adminlte::page')
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<h1>view accounts!</h1>
@foreach($bfaccounts as $userAccount)
<p>{{ $userAccount->acct_firstname }}</p><br>
<p>{{ $userAccount->acct_middlename }}</p><br>
<p>{{ $userAccount->acct_lastname }}</p>
@if ($userAccount->id)
<form action="/Accounts" method="POST">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<a href="/Accounts">
<button type="button">delete</button>
</a>
</form>
@endif
<a href="/Accounts/{{ $userAccount->id }}/edit">
<button type="button">edit</button>
</a>
@endforeach
</body>
</html>
应用程序/ HTTP /控制器/ AccountsController.php
<?php
namespace App\Http\Controllers;
use App\bufashaccounts;
use Illuminate\Http\Request;
class AccountsController extends Controller
{
public function index()
{
$bfaccounts = bufashaccounts::all();
return view('bufashaccts.allAccounts', compact('bfaccounts'));
}
public function create()
{
return view('bufashaccts.addAccounts');
}
public function store(Request $request)
{
bufashaccounts::create($request->all());
return "success!";
}
public function show($id)
{
$bfshowAccounts = bufashaccounts::findOrFail($id);
return view('bufashaccts.viewAccounts', compact('bfshowAccounts'));
//return $bfshowAccounts;
}
public function edit($id)
{
$bfeditAccounts = bufashaccounts::findOrFail($id);
return view('bufashaccts.editAccounts', compact('bfeditAccounts'));
}
public function update(Request $request, $id)
{
$bfeditAccounts = bufashaccounts::find($id);
$bfeditAccounts->update($request->all());
return redirect('Accounts');
}
public function destroy($id)
{
//$bfdeleteAccounts = bufashaccounts::findOrFail($id);
//$bfdeleteAccounts->delete();
//return 'delete';
$bfaccounts = bufashaccounts::findOrFail($id);
$bfeditAccounts->delete();
//return view('bufashaccts.allAccounts', compact('bfaccounts'));
return redirect('/Accounts');
}
}
为什么你在链接中有一个按钮? –
你是如何为它设置路线的? – Sina
我还没有为它设置路由,因为它是一个资源路由 – JING