Cześć,
Czy w Laravel'u można stworzyć tak routes abym nie musiał wypisywać wszystkich stron po kolei tylko aby były one pobierane z bazy danych?
Przykładowo oprogramowanie ma 100 stron, to w takim przypadku musiałbym wypisać 100 razy:
Route::get(…..
Route::get('/{slug}', function($slug){ dd($slug); }); // tak jak pisał ctom
$param['controller'] = $param[0]; $param['action'] = $param[1]; if($param['controller'] == 'pages' && $param['action'] == 'edit'){ //jak wyświetlić metodę edit? pod nią mam cały widok i wszystko skonfigurowane }
Route::get('pages/edit/{id}', 'PagesController@edit');
get('/{controller}/{action}/{params?}', function($controller, $action, $params = null) { if(!class_exists($controller)) { throw new \Exception('There is no ' . $controller); } if(!method_exists($controller, $action)) { throw new \Exception('There is no Action ' . $action); } $controller = new $controller; })->where('params', '(.*)');
<?php namespace App\Http\Controllers; class HomeController extends Controller { public function index() { } }
Argument 1 passed to App\Http\Controllers\PagesController::__construct() must be an instance of App\Http\Controllers\Pages\IndexController, none given, called in /Projects/default/app/Http/routes.php on line 29 and defined PagesController: private $index; private $default; private $developer; function __construct(IndexController $index, DefaultController $default, DeveloperController $developer) { $this->default = $default; $this->index = $index; $this->developer = $developer; } route.php takie jak wysłał Pyton_000
get('/{controller}/{action}/{params?}', function($controller, $action, $params = null) { if(!class_exists($controller)) { throw new \Exception('There is no ' . $controller); } if(!method_exists($controller, $action)) { throw new \Exception('There is no Action ' . $action); } })->where('params', '(.*)');
// Form::open parametr action nie chce poprawnie działać return isset($this->actionList[$action]) ? $this->actionList[$action] : null; //dokopałem się do mnejsca błędu... // a dokładniej $this->actionList[$action]) Method Illuminate\View\View::__toString() must not throw an exception //dalej jeżeli zrobię to //to ze sposobem powyżej tablica jest pusta jeżeli zmienię na: Route::get('pages/edit/{id}', 'PagesController@edit'); tablica pokazuje masę wyników