缺少App \ Http \ Controllers的参数1

时间:2017-04-16 01:00:43

标签: php mysql laravel

我是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

2 个答案:

答案 0 :(得分: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);
}

希望这可以解决您的问题。

答案 1 :(得分:0)

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