I would like to pass the id of an object to a controller in laravel. Basically I've a page that displays the information relating to a book. The user has the option to add themes to that book. The line below is the link they click in order to open the create theme form:
<a href="{{action('ThemeController@create')}}" class="btn btn-primary">Add Theme</a> and the ThemeController method:
public function create(){ $books = Book::all(); return View::make('theme.create', compact('books')); } Currently this brings up a Form with a list of all of my books in a dropdown. I would rather just pass the id of the book the user was on prior to being brought to this form and use that instead. Is there any way I can do that? I've also included my routes.php file:
Route::model('book', 'Book'); //Show pages Route::get('/books', 'BookController@index'); Route::get('book/create', 'BookController@create'); Route::get('book/edit/{book}', 'BookController@edit'); Route::get('book/delete/{book}', 'BookController@delete'); Route::get('book/view/{book}', 'BookController@view'); ////Handle form submissions Route::post('book/create', 'BookController@handleCreate'); Route::post('book/edit', 'BookController@handleEdit'); Route::post('book/delete', 'BookController@handleDelete'); //Themes Route::model('theme', 'Theme'); Route::get('/themes', 'ThemeController@index'); Route::get('theme/create', 'ThemeController@create'); Route::get('theme/edit/{book}', 'ThemeController@edit'); Route::get('theme/delete/{book}', 'ThemeController@delete'); Route::get('theme/view/{book}', 'ThemeController@view'); Route::post('theme/create', 'ThemeController@handleCreate'); Route::post('theme/edit', 'ThemeController@handleEdit'); Route::post('theme/delete', 'ThemeController@handleDelete');
Conrollersbut had been using it for theMigrations