Ad
Laravel 5.6. Route Model Bindung
Hello I'm trying to create own laravel package it has two Controller resource, which have single controller and model Post
Route::resource('posts', \vendor\package\Controllers\PostsController::class);
Route::resource('categories', \vendor\package\Controllers\PostsController::class);
My method in the PostsController
is show(Post $post)
If I open link http://localhost/posts/1, attributes element of $post
is not empty in the show
method.
But when I open link http://localhost/categories/1, attributes element of $post
is empty.
How can I get Post data for resource
categories
?
P.S. difference between posts and categories is value of column post_type
in the DB.
Ad
Answer
You can define what the route parameter will be named for the generated routes when using resource routing.
This should be the only change you need to make:
Route::resource(
'categories',
\vendor\package\Controllers\PostsController::class,
['parameters' => ['categories' => 'post']]
);
Now the route parameter is post
:
GET categories/{post}
GET categories/{post}/edit
...
Laravel 5.6 Docs - Controllers - Naming Resource Route Parameters
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad