Dmitry Malys
Dmitry Malys

Reputation: 1323

Missing argument 1 for App\Http\Controllers\

im new in laravel. I have a problem on my app version 5.2.45

I having Missing argument 1 for App\Http\Controllers\PhotoController::create() when i try to pass variable to view with information from database:

Route:

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

Controller:

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'));
}

View:

@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

Upvotes: 1

Views: 2751

Answers (2)

Jahid Mahmud
Jahid Mahmud

Reputation: 1136

You should write this in your controller

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);
}

Hopefully this will solve your problem.

Upvotes: 1

TurtleTread
TurtleTread

Reputation: 1314

You need to pass the id into the url since your Controller method requires it Route::get('photo/create/{id}', 'PhotoController@create');

Upvotes: 0

Related Questions