删除功能:Laravel 5

时间:2017-03-05 15:42:27

标签: php laravel-5

这里是laravel框架的新手。我在这里调用我的资源控制器中的删除功能时遇到了很大问题。好像它没有删除所选的id。感谢您的帮助。

资源/视图/ 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');
    }
}

2 个答案:

答案 0 :(得分:0)

您需要将表单更改为:

# Get all the up-to-date tools you'll need
sudo apt-get update
sudo apt-get install git cmake build-essential

# Get latest greatest OpenCV from GitHub
cd
git clone https://github.com/opencv/opencv.git

# Go build and install that puppy
cd opencv
mkdir build
cd build
cmake ..
make -j 8 
sudo make install

希望这有帮助!

答案 1 :(得分:0)

  1. 在路线文件中添加

    Route::delete('account/delete/{id}', ['as' => 'account.delete', 'uses' => 'AccountsController@destroy'])
    
  2. 修改您的刀片文件

    <form action="{{ route('account.delete') }}" method="POST">
    {{ csrf_field() }}
    {{ method_field('DELETE') }}
    <button type="submit" class="btn btn-danger">Delete</button>
    

  3. 试试这种方式。希望它能奏效。