這裏新增了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