Laravel 4 Redirect :: action () "Route not defined"

I am currently having problems with Laravel 4. I would like to use bullets for forum categories and forum topics (unique bullets). To determine if a user is in a category or topic, I have this route:

Route::get('forum/{slug}', function($slug) {

    $category = ForumCategory::where('slug', '=', $slug)->first();

    if (!is_null($category))
        return Redirect::action('ForumCategoryController@findBySlug', array('slug' => $slug));

    else {

        $topic = ForumTopic::where('slug', '=', $slug)->first();

        if (!is_null($topic))
            return Redirect::action('ForumTopicController@findBySlug', array('slug' => $slug));

        else
            return 'fail';

    }

});

And I get the following error when I try to reach a category:

Route [ForumCategoryController@findBySlug] not defined.

Here is my ForumCategoryController:

class ForumCategoryController extends BaseController {

    public function findBySlug($slug) {

        $category = ForumCategory::where('slug', '=', $slug)->first();

        return View::make('forum.category', array(
            'title'         => 'CatΓ©gorie',
            'category'      => $category
        ));

    }

}

Where is the problem? Is there any way to make this better? Help me please:)

+4
source share
1 answer

Laravel says you need to determine the route to use Route::action(), something like:

Route::get('forum/bySlug/{slug}', 'ForumTopicController@findBySlug');

Because it really builds the url and executes it:

http://your-box/forum/bySlug/{slug}

, .

+4

Source: https://habr.com/ru/post/1524159/


All Articles