lundi 30 novembre 2015

Same route but call different controller in Laravel 5.1 routing

I have two url's one for category and one for brand such as:

http://localhost/project/womens-fashion #category
http://localhost/project/babette-clothes #brand

I just wanted to make one route but call different controller. I have written the route but its not work for me its send error. See below code:

<?php
use \DB;
use Illuminate\Routing\UrlGenerator;
use Illuminate\Support\Facades\Redirect;

Route::get('/','HomeController@index');
Route::get('/product', array('uses' => 'ProductController@index'));
Route::get('/{slug}', function($slug) {
    $result = DB::select('SELECT controller FROM url_setting where slug = ?', [$slug]);

    if ($result[0]->pw_us_controller == 'CategoryController@view') {
        return Redirect::action('CategoryController@view', array($slug));
    } elseif ($result[0]->pw_us_controller == 'CategoryController@view') {
        return Redirect::action('BrandController@index', array($slug));
    } else {
        return Redirect::action('HomeController@index');
    }
});

Error: InvalidArgumentException in UrlGenerator.php line 576: Action App\Http\Controllers\CategoryController@view not defined.

I am pretty confused, what went wrong? any idea!!!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire