【问题标题】:Missing argument 1 for App\Http\Controllers\App\Http\Controllers\ 缺少参数 1
【发布时间】:2017-04-16 12:05:14
【问题描述】:

我是 laravel 的新手。我的应用版本 5.2.45 有问题

当我尝试传递变量以查看来自数据库的信息时,App\Http\Controllers\PhotoController::create() 缺少参数 1:

路线:

Route::get('photo/create/{id}', 'PhotoController@create');

控制器:

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;

use DB;

use Session;

class PhotoController extends Controller { private $table = 'photos';

// Show Create Form
public function create($gallery_id) {
    // render view
    return view('photo.create', compact('gallery_id'));
}

查看:

@section('content')

<div class="row">
    <div class="col-md-8 col-md-offset-2">
        <h1>Upload photo</h1>

        {!! Form::open(array('action' => 'PhotoController@store', 'enctype' => 'multipart/form-data')) !!}
        {{ Form::label('title', 'Title:') }}
        {{ Form::text('title', null, array('class' => 'form-control', 'required' => '', 'maxlength' => '255')) }}

        {{ Form::label('description', 'Description:') }}
        {{ Form::text('description', null, array('class' => 'form-control', 'required' => '', 'minlength' => '5', 'maxlength' => '255') ) }}

        {{ Form::label('image', 'Photo:') }}
        {{ Form::file('cover') }}

        <input type="hidden" name="gallery_id" value="{{ $gallery_id }}">

        {{ Form::submit('Upload photo', array('class' => 'btn btn-success btn-lg btn-block', 'style' => 'margin-top: 20px;')) }}
        {!! Form::close() !!}

    </div>
</div>
@endsection

【问题讨论】:

    标签: php mysql laravel


    【解决方案1】:

    你应该在你的控制器中写这个

    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    
    use App\Http\Requests;
    
    use DB;
    
    use Session;
    
    class PhotoController extends Controller {
    
    // Show Create Form
    public function create($id) {
        // render view
        return view('photo.create')->with('gallery_id', $id);
    }
    

    希望这能解决您的问题。

    【讨论】:

      【解决方案2】:

      您需要将 id 传递到 url,因为您的 Controller 方法需要它 Route::get('photo/create/{id}', 'PhotoController@create');

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2018-02-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-06-03
        相关资源
        最近更新 更多