I have a very weird problem. I could access the page and everything was fine until i added a few new routes in my web.php routing file. Problem is with 5th route(named post.create). The ** are just to highlight the line/route i am talking about:
Route::group(['prefix'=>'admin', 'middleware'=>'auth'], function()
{
Route::get('home', 'HomeController@index')->name('admin.home');
Route::get('post/all','PostsController@index')->name("post.all");
Route::get('post/{id?}','PostsController@show')->name('post.fetch');
**Route::get('post/create','PostsController@create')->name('post.create');**
Route::post('post/store', 'PostsController@store')->name('post.store');
Route::put('post/{id?}','PostsController@update')->name('post.update');
Route::delete('post/delete/{id}','PostsController@destroy')->name('post.delete');
Route::get('category/create','CategoriesController@create')->name('category.create');
Route::post('category/store','CategoriesController@store')->name('category.store');
Route::get('category/all','CategoriesController@index')->name('category.all');
Route::get('category/{id?}','CategoriesController@show')->name('category.fetch');
Route::delete('category/delete/{id}','CategoriesController@destroy')->name('category.delete');
Route::put('category/{id}','CategoriesController@update')->name('category.update');
});
Route::get('posts/create','PostsController@create')->name('post.create');
public function create()
{
$categories = Category::all();
return view('admin.posts.create', compact('categories'));
}
Laravel will serve the first route matched in the order you define them. Since you have post.fetch
first it is serving that route with 'create' as the id
parameter.
In your routes file place post.create
before post.fetch
so you have:
Route::get('post/create','PostsController@create')->name('post.create');
Route::get('post/{id?}','PostsController@show')->name('post.fetch');
Route::post('post/store', 'PostsController@store')->name('post.store');
Route::put('post/{id?}','PostsController@update')->name('post.update');