如何在Laravel中解决此更新错误

时间:2018-02-19 10:22:15

标签: database laravel

我正在创建一个网站。我创建了一个注册页面。我想更新我的详细信息。

但是,它给了我这个错误,我还在上面上传了一张错误图片。 - Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException 没有消息

** Error Picture

我该如何解决这个问题?

这是我的AdminPanel.blade.php

<table class="table table-bordered">

<tr>
<td> Name </td>
<td> Email </td>
<td> Images </td>
</tr>


@foreach($data as $value )
<tr>
<td> {{ $value->username }} </td>
<td> {{ $value->email }} </td>
<td> <img src='{{ $value->filemove }}' style='width:100px;height:100px;'> </td>
<td> <a href="edit/{{ $value->id }}"><input type="submit" name="update" value="Update" class="btn-primary"></a> </td>
<td> <a href="delete{{ $value->id }}"><input type="submit" name="delete" value="Delete" class="btn-danger"></a> </td>
</tr>
@endforeach
</table>

这是我的AdminUpdate.blade.php

<form action="edit{{ $users[0]->id }}" method="post" enctype="multipart/form-data">

    {{ method_field('PUT') }}
    {{ csrf_field() }}

  <div class="form-group">
    <label>Username : *</label>
    <input type="text" class="form-control" name="username" value="{{$users[0]->username}}" placeholder="Enter Your Username" required>
  </div>

    <div class="form-group">
    <label>Email : *</label>
    <input type="email" class="form-control" name="email" value="{{$users[0]->email}}" placeholder="Enter Your Username" required>
  </div>

  <div class="form-group">
    <label>Password : *</label>
    <input type="password" class="form-control" name="password" value="{{$users[0]->password}}" placeholder="Enter Your Password" required>
  </div>

  <div class="form-group">
    <label>Upload Profile Picture :</label>
    <input type="file" class="form-control-file" name="file_img" aria-describedby="fileHelp">
    <small id="fileHelp" class="form-text text-muted">If U Want , U Can Skip Upload A Profile Picture</small>
  </div>

  @section('btnName',"Update") 
  <input type="submit" class="btn btn-primary" onclick="myFunction()" name="submit" value="@yield('btnName')">
                    </form>

这是我的AdminPanelController.php

<?php

namespace App\Http\Controllers;

use Auth;
use Illuminate\Http\Request;
use App\User;
use Validator;
use Illuminate\Support\Facades\Input;

class AdminPanelController extends Controller
{
    public function index()
    {
      $data = User::all();
      //$data = login::orderBy('created_at', 'desc')->get();
      return view('AdminPanel', ['data' => $data]);
    }

    public function adminedit(Request $request, $id)
    {
        $this->validate($request, [
            'email' => 'required'
        ]);

        $users = User::find($request['id']);
        $users->username = $request['username'];
        $users->email = $request['email'];
        $users->update();
        return redirect('AdminPanel');


    }

}

这是我的路线

Route::put('edit/{id}','AdminPanelController@adminedit');

1 个答案:

答案 0 :(得分:0)

你应该替换你的行动网址

 //make sure you have $users[0]->id data here
<form action="{{ action('AdminPanelController@adminedit',['id'=> $users[0]->id]) }}" ....>