0

This is my code of laravel routes file and all other routs working nicely but 'update' route giving an error that 'Route [dashboard.update] not defined' here is code of routes

Route::group(['middleware' => 'auth', 'prefix' => 'dashboard'],function (){

// get routes
Route::get('/', 'HomeController@index')->name('dashboard.index');
Route::get('add', 'HomeController@addNotice')->name('dashboard.add');
Route::get('{id}/edit', 'HomeController@editNotice')->name('dashboard.edit');
Route::get('{id}', 'HomeController@showNotice')->name('dashboard.show');

// post routes
Route::post('add', 'HomeController@storeNotice')->name('dashboard.store');
Route::post('{id}','HomeController@updateNotice')->name('dashboard.update'); //error here
Route::post('{id}', 'HomeController@deleteNotice ')->name('dashboard.delete');
});

here is the code of view return by HomeController

<form action="{{ route('dashboard.update',['noticeId' => $noticeId->id]) }}" method="POST" style="padding-left: 10px; padding-right: 10px;">
            {{ csrf_field() }}
            <div class="row">
                <div class="form-group">
                    <input type="text" class="form-control" name="noticeTitle" placeholder="Give Title to Notice" value="{{ $noticeId->title }}">
                </div>
            </div>

            <div class="row">
                <div class="form-group">
                    <textarea name="noticeBody" cols="30" rows="8" class="form-control" placeholder="Add Notice Details Here" style="resize: none">{{ $noticeId->body }}</textarea>
                </div>
            </div>

            <div class="row">
                <div class="form-group">
                    <input type="submit" name="editNotice" value="Save Changes" class="btn btn-info btn-block btn-sm">
                    <input type="hidden" name="_method" value="PUT">
                </div>
            </div>
        </form>
Umair Gul
  • 352
  • 1
  • 4
  • 15
  • Thank you @FPJ and it really helps, I was using post method for update and delete while they have 'put' and 'delete' methods. – Umair Gul May 21 '17 at 16:42

2 Answers2

0

Change your route type to PUT or PATCH

Route::patch('{id}','HomeController@updateNotice')->name('dashboard.update');

And this to your form

{!! method_field('PATCH') !!}

The error here is because your delete route is overwriting the update route since they're of the same type and path. Typically for delete routes you should use the 'DELETE' method.

Sandeesh
  • 11,486
  • 3
  • 31
  • 42
0
Route::post('{id}','HomeController@updateNotice')->name('dashboard.update');

to

Route::put('{id}','HomeController@updateNotice')->name('dashboard.update');
Exprator
  • 26,992
  • 6
  • 47
  • 59