dsf6778
2017-01-24 22:33
浏览 800
已采纳

在Laravel中缺少路线所需的参数

in my laravel application whenever i go to this route: /admin or admin/users I get the following error message but the the other routes work like admin/users/create or admin/users/edit:

Missing required parameters for [Route: admin.users.edit] [URI: admin/users/{id}/edit]. (View: C:\xampp\htdocs\CMSesources\views\admin\index.blade.php)

To note I'm not including all the html code of index.blade.php as it's too long the only blade code is from what i have pasted.

Index.blade view:

 <ul class="nav nav-second-level">
                            <li>
                                <a href="{{route('admin.users.edit')}}">All Userss</a>
                            </li>

                            <li>
                                <a href="{{route('admin.users.create')}}">Create User</a>
                            </li>

                        </ul>

Route list:

URI:

- admin/users
- admin/users/create
- admin/users/store
- admin/users/update
- admin/users/{id}/edit

Name:

1. admin.users.index
 2. admin.users.create
 3. admin.users.store
 4. admin.users.update
 5. admin.users.edit

Action:

 1. App\Http\Controllers\AdminUsersController@index 
 2. App\Http\Controllers\AdminUsersController@create 
 3. App\Http\Controllers\AdminUsersController@store 
 4. App\Http\Controllers\AdminUsersController@update 
 5. App\Http\Controllers\AdminUsersController@edit

admin/users

Routes:

Route::get('admin/users/', [

    'uses' => 'AdminUsersController@index',
    'as' => 'admin.users.index'
]);


Route::get('admin/users/create', [

    'uses' => 'AdminUsersController@create',
    'as' => 'admin.users.create'
]);

Route::get('admin/users/{id}/edit', [

    'uses' => 'AdminUsersController@edit',
    'as' => 'admin.users.edit'
]);

Controller:

    public function edit($id)
    {

        $user = User::findOrFail($id);

        $roles = Role::pluck('name', 'id')->all();

        return view('admin.users.edit', compact('user', 'roles'));
    }


    public function update(Request $request, $id)
    {
        //
    }

Edit View:

@extends('layouts.admin')

@section('content')

<h1>Edit Users</h1>

{!! Form::open(['method' => 'PATCH', 'action' => ['AdminUsersController@update', $user->id], 'files' => true]) !!}

@include('includes.form-error')

<div class="form-group">

    {!! Form::label('name', 'Name:') !!}
    {!! Form::text('name', null, ['class' => 'form-control']) !!}

</div>


<div class="form-group">

    {!! Form::label('email', 'Email:') !!}
    {!! Form::email('email', null, ['class' => 'form-control']) !!}

</div>


<div class="form-group">

<div class="form-group">

    {!! Form::label('role_id', 'Role:') !!}
    {!! Form::select('role_id',$roles , null, ['class' => 'form-control']) !!}

</div>

<div class="form-group">

    {!! Form::label('status', 'Status:') !!}
    {!! Form::select('status', [1 => 'Active', 0 => 'Not Active'], 0, ['class' => 'form-control']) !!}

</div>

    <div class="form-group">

    {!! Form::label('photo_id', 'Photo:') !!}
    {!! Form::file('photo_id', null, ['class' => 'form-control']) !!}

</div>


<div class="form-group">

    {!! Form::label('password', 'Password:') !!}
    {!! Form::password('password', ['class' => 'form-control']) !!}

</div>

<div class="form-group">

    {!! Form::submit('Create User', ['class' => 'btn btn-primary']) !!}

</div>


{!! Form::close() !!}


@endsection
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • duanpei4455 2017-01-24 23:14
    已采纳

    Here is your error. You missed to pass the variable in route:

      <li>
          <a href="{{route('admin.users.edit')}}">All Users</a>
      </li>
    

    Instead of {{route('admin.users.edit')}} use:

    {{route('admin.users.edit', $id)}}

    This is actually editing route. If you want to get all users use:

    {{route('admin.users.index')}}

    点赞 打赏 评论
  • doukong5394 2017-01-24 23:14

    You are using:

    <a href="{{route('admin.users.edit')}}">All Userss</a>
    

    in your Blade file, but your route is defined like so:

    Route::get('admin/users/{id}/edit', [
    
        'uses' => 'AdminUsersController@edit',
        'as' => 'admin.users.edit'
    ]);
    

    so it's edit action and you need to pas id of user you want to edit for example:

    <a href="{{route('admin.users.edit', [auth()->user()->id])}}">All Userss</a>
    
    点赞 打赏 评论
  • dsuikgi9199 2017-01-24 23:15

    Change {{route('admin.users.edit')}} to {{route('admin.users.edit', $id)}} and dont forget to change $id to the real id variable :)

    And its strange, because you write All users and giving the edit route :)

    点赞 打赏 评论

相关推荐 更多相似问题