phplaravellaravel-5.8event-calendar

Too few arguments to function App\Http\Controllers\EventController::edit(), 0 passed and exactly 1 expected


hi guys please help me im new to the laravel i don't know why i have this error

Symfony\Component\Debug\Exception\FatalThrowableError Too few arguments to function App\Http\Controllers\EventController::edit(), 0 passed and exactly 1 expected

this is my EventController

 ' public function show()
{
    $events = Event::all();
    return view('superadminpage.admin_event.admin_update_event')->with('events', $events);
}

/**
 * Show the form for editing the specified resource.
 *
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function edit($id)
{
    $events = Event::find($id);
    return view('superadminpage.admin_event.admin_editform', compact('events', 'id'));
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
    $this->validate($request,[
        'title' => 'required',
        'color' => 'required',
        'start_date' => 'required',
        'end_date' => 'required',
    ]);

    $events = Event::find($id);

    $events->title = $request->input('title');
    $events->color = $request->input('color');
    $events->start_date = $request->input('start_date');
    $events->end_date = $request->input('end_date');

    $events->save();

    return redirect('admin_calendar')->with('success', ' has been added');
}

'

this is my route

"Route::get('/admin_update_event', 'EventController@show');
 "Route::get('/admin_editform', 'EventController@edit');

this is my admin_update_event.blade.php

 @foreach ($events as $event)
    <tbody>
        <tr>
            <td>{{ $event->id}}</td>
            <td>{{ $event->title}}</td>
            <td>{{ $event->color}}</td>
            <td>{{ $event->start_date}}</td>
            <td>{{ $event->end_date}}</td>

            <th> <a href="{{ route('edit',['id' => $events->id, 'event' => 1]) }}">
                    Edit </a>
            </th>

        </tr>
    </tbody>
    @endforeach

this is my admin_editform.blade.php

            <form method="POST" action="{{action('EventController@update')}}">

                {{csrf_field() }}
                <div class="container">
                    <div class="jumnbotron"> 
                        <h1> Update Event </h1>
                    <br>
                <input type="hidden" name="_method" value="UPDATE" />

                <div class="form-group">
            <label for="">Enter name of the Event</label>
            <input type="text" class="form-control" name="title" placeholder="Enter The name" value="{{ $events->title}}">
                </div>

                <div class="form-group">
            <label for="">Choose a Color</label>
            <input type="color" class="form-control" name="color" placeholder="Choose a color" value="{{ $events->color}}">
                </div>

                <div class="form-group">
            <label for="">Enter startdate of the Event</label>
            <input type="datetime-local" class="form-control" name="start_date" class="date" placeholder="Enter The start date" value="{{ $events->start_date}}">
                </div>

                <div class="form-group">
            <label for="">Enter enddate of the Event</label>
            <input type="datetime-local" class="form-control" name="end_date" class="date" placeholder="Enter The end date" value="{{ $events->end_date}}">
                </div>
            {{ method_field('PUT') }}
            <input type="submit" name="submit" class="btn btn-primary" value="add Event data"/>

                    </div>
                </div>
            </form>

Solution

  • The issue is your "edit" route having no parameters and the edit() method expects a $id parameter. Try this:

    Route::get('/admin_editform/{id}', 'EventController@edit');