0
votes

I am new too laravel and I'm creating a blog, specifically the index page where all the blogs will be displayed and when displayed , when a specific blog title is clicked instead of opening the blog post it displays

BadMethodCallException Method App\Http\Controllers\StoreController::show does not exist.

Route::group(['middleware' => ['web']], function () {

    Route::get('/','StoreController@index');
    Route::resource('store','StoreController');    
    Route::resource('category','CategoryController');
    Route::resource('post','PostController');
    //Route::resource('user','UserController');
    //Route::controller('mail','MailController');

});

Route::group(['middleware' => ['web']], function () {

    Route::get('/','StoreController@index');
    Route::resource('store','StoreController');
    Route::resource('category','CategoryController');
    Route::resource('post','PostController');
    //Route::resource('user','UserController');
    //Route::controller('mail','MailController');

});
4
does StoreController available in your project - Nipun Tharuksha
yes it does.... - user11935474
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Post; use App\show; use App\Http\Requests; use App\Http\Controllers\Controller; class StoreController extends Controller { public function index() { return view('store.main') ->with('posts', Post::orderBy('created_at','DESC')->get()); } public function getView($id){ return view('store.view') ->with('posts', Post::find($id)); } } - user11935474
is this the controller - Nipun Tharuksha
yes it is, am trying to add an image , how do i add an image here in the comment - user11935474

4 Answers

0
votes

Post the HTML code that you are using in order to redirect to the blog page. In addition to that, seems like you are not using Laravel routes as you should.

0
votes

Make sure your controller "StoreController" has show method.

https://laravel.com/docs/5.8/controllers#resource-controllers

0
votes

Did you create your StoreController? If you did seems like that your controller is missing show() function, which should handle specific blog show. Did you create it with -r flag, like this:

php artisan make:controller StoreController -r

This will automatically create a resource controller with all necessary methods:

  1. index()
  2. show()
  3. create()
  4. store()
  5. update()
  6. delete()

More about resource controllers in official documentation

0
votes

Mine was working well but started throwing errors suddenly. Create a new controller, copy and paste all the methods from the old controller to the new controller. This solved my problem. Hope it solves yours. For instance my old controller was WebsiteController and renamed to WebController. Remember to change the controller in the routes too. Hope someone helps to explain what causes this..