为什么我在 RouteCollection 中收到 NotFoundHttpException?

Why I am getting NotFoundHttpException in RouteCollection?

当我尝试重定向 Laravel 5.3 中的一些 url 时,我遇到了错误。我在 Route Collection 中得到了 NotFoundHttpException。我错过了什么吗?

这里可以看到错误输出:

enter image description here

这是我的控制器代码:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\User;
use App\Role;
use DB;

use App\Provinsi;
use App\Kabupaten;
use App\puskesmasreg;

use Yajra\Datatables\Html\Builder;
use Yajra\Datatables\Datatables;

use Session,Log;

class UserseditadminpassController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        //
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
        $user =  User::leftjoin('provinsis','users.access_id','=','provinsis.idprovinsi')
                ->leftjoin('kabupatens','users.access_id','=','kabupatens.idkabupaten')
                ->leftjoin('puskesmasregs','users.access_id','=','puskesmasregs.kodepuskesmas')
                ->join('role_user','role_user.user_id','=','users.id')
                ->join('roles','role_user.role_id','=','roles.id')
                ->select(['users.id','username','users.name AS nama','roles.name','users.email','password','photo','access_id','is_verified','role_id','access_name','users.created_at','users.updated_at'])
                ->where('users.id','=',$id)->get()->first();


        //return view('users.edit')->with(compact('user'));
        return view('users.view-edit-password-admin')->with(compact('user'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request,$id)
    {
        //
        $user = user::find($id);
        $this->validate($request, [
        //'password' => 'required|passcheck:' . $user->password,
        'new_password' => 'required|confirmed|min:6',
        ]
        );
        $user->password = bcrypt($request->get('new_password'));
        $user->save();
        Session::flash("flash_notification", [
        "level"=>"success",
        "message"=>"Password berhasil diubah"
        ]);
        return redirect('users.view-edit-password-admin');
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}

这是我的路线代码:

Route::group(['prefix'=>'admin', 'middleware'=>['auth','role:administrator']], function () {
    Route::resource('usersadmineditpassword', 'UserseditadminpassController');

});

这是我的观点代码:

@extends('layouts.adminmonevpkam')

@section('content')
<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
       <h1>
        PENGGUNA / USER eMONEV PKAM<br>
        <small>data pengguna e-Monev PKAM</small>
      </h1>
      <ol class="breadcrumb">
        <li><a href="{{ url('home') }}"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="{{ url('/admin/petugasregs') }}">Data User</a></li>
        <li class="active">Ubah Data Pengguna</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">

      <!-- /.row (main row) -->
      <div class='row'>
      <div class='col-md-12'>
            <!-- Box -->
            <div class="box box-primary" >
                <div class="box-header with-border">
                    <h3 class="box-title">Ubah Password</h3>
                </div>
                {!! Form::model($user, ['url' => route('usersadmineditpassword.update', $user->id), 'method'=>'put','files'=>'true','class'=>'form-horizontal'])
                !!}
                 <div class="box-body">
                 <div class="form-group">
    {!! Form::label('user_name2', 'Username', ['class'=>'col-md-2 control-label']) !!}
    <div class="col-md-4">
        {!! Form::text('username', null, ['class'=>'form-control','readonly']) !!}
    </div>
</div>
                <div class="form-group{{ $errors->has('new_password') ? ' has-error' : '' }}">
                {!! Form::label('new_password', 'Password baru', ['class'=>'col-md-4 control-label']) !!}
                <div class="col-md-6">
                  {!! Form::password('new_password', ['class'=>'form-control']) !!}
                  {!! $errors->first('new_password', '<p class="help-block">:message</p>') !!}
                </div>
              </div>

              <div class="form-group{{ $errors->has('new_password_confirmation') ? ' has-error' : '' }}">
                {!! Form::label('new_password_confirmation', 'Konfirmasi password baru', ['class'=>'col-md-4 control-label']) !!}
                <div class="col-md-6">
                  {!! Form::password('new_password_confirmation', ['class'=>'form-control'])!!}
                  {!! $errors->first('new_password_confirmation', '<p class="help-block">:message</p>') !!}
                </div>
              </div>
                </div><!-- /.box-body -->
                <div class="box-footer">
                    {!! Form::submit('Simpan', ['class'=>'btn btn-primary']) !!}
                    <input type="button" name="cancel" value="Batal" onClick="window.location='{{ url('/admin/users') }}';" class="btn btn-primary" />
                </div><!-- /.box-footer-->
                {!! Form::close() !!}
            </div><!-- /.box -->
      </div>
     </div><!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
@endsection

@section('scripts')
    <script type="text/javascript" src="{{ asset('js/monevpkam.js') }}"></script>
@endsection

当我按下提交按钮时,我遇到了以下错误:

Sorry, the page you are looking for could not be found.

1/1
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 780
at Router->findRoute(object(Request)) in Router.php line 610
at Router->dispatchToRoute(object(Request)) in Router.php line 596
at Router->dispatch(object(Request)) in Kernel.php line 267
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 149
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116
at Kernel->handle(object(Request)) in index.php line 58

您正在重定向到丢失的 url。这就是您收到 NotFoundHttpError 的原因。 如果你想将它重定向到编辑控制器,你需要调用它作为路由名称。所以你应该使用

return redirect('usersadmineditpassword.edit'); 

而不是

return redirect('users.view-edit-password-admin');