Reputation: 289
im using laravel 5.5 and i created a view for edit categories inside views/back/categories/edit here my edit function in CategoriesController
public function edit($id)
{
$category = Categories::getall();
$categories = Categories::find($id);
return view('back.categories.edit', ['categories' => $categories, 'category' => $category]);
}
and here is my route
Route::group(['middleware'=>'admin'],function(){
Route::get('/dashboard','BackendController@index')->name('backend');
Route::group(['prefix' => 'categories'], function () {
Route::any('/show/{id}', ['as' => 'backend.categories.show', 'uses' => 'backend\CategoriesController@show']);
Route::get('/index', ['as' => 'back.categories.index', 'uses' => 'backend\CategoriesController@index']);
Route::any('/store', ['as' => 'back.categories.store', 'uses' => 'backend\CategoriesController@store']);
Route::any('/create', ['as' => 'back.categories.create', 'uses' => 'backend\CategoriesController@create']);
Route::any('/edit/{id}', ['as' => 'back.categories.edit', 'uses' => 'backend\CategoriesController@edit']);
Route::any('/update', ['as' => 'back.categories.update', 'uses' => 'backend\CategoriesController@update']);
Route::any('/destroy/{id}', ['as' => 'back.categories.destroy', 'uses' => 'backend\CategoriesController@destroy']);
});
});
my edit button
<a href="{{ url('back/categories/edit/'.$category->cat_id) }}" class="btn btn-success btn-sm">
<span class="fa fa-edit"></span> edit</a>
when i click on the edit button it return page not found with "Sorry, the page you are looking for could not be found." text and the URL :"back/categories/edit/4"
Upvotes: 2
Views: 1974
Reputation:
You're missing the back
portion of the prefix on your categories
group.
Route::group(['prefix' => 'back/categories'], function () {
That would match your routes.
Upvotes: 0
Reputation: 18250
From your routes definition it looks like your url is /categories/edit/{id}
For links in templates I suggest to use the route
helper function which takes the route name or the action
method which takes controller@method
Also have a look at resource controllers
Route::resource('categories', 'CategoryController');
could replace your entire routes definition
https://laravel.com/docs/5.5/controllers#resource-controllers
Upvotes: 0
Reputation: 163768
Since your route are named, you can use the route()
helper to build working URL:
{{ route('back.categories.edit', ['id' => $category->cat_id]) }}
Upvotes: 1