Artisan Nested Resource Controllers Creation Does Artisan support the creation of nested resource controllers?
I like the 'php artisan make:model -mcr' command because it's a time saver.
However it would be great if you could reference a parent resource controller to make it easier to create nested resource controller. Going back and placing the parameters into each function section in the controllers is uncomfortable.
Any ideas?
Route::resource('country', 'CountryController');
Route::resource('country.state', 'StateController');
Route::resource('country.state.county', 'CountyController');
Route::resource('country.state.county.city', 'CityController');
php artisan make:controller YourController -p=YourParent
Everytime when you use artisan command, you can type -h to get more info about options.
Like
php artisan make:controller -h
So what would have been the argument for the last one?
-p=country.state.county ??
php artisan make:controller -m=City -r -p=country.state.county City
I try it right now and it seems to have to be a model class.
They add this ability in this commit .
-p(for parent) is not an option for Model Class.
This command
php artisan make:controller TestController -r --model=Comment --parent=Article
create this controller
<?php
namespace App\Http\Controllers;
use App\Article;
use App\Comment;
use Illuminate\Http\Request;
class TestController extends Controller
{
/**
* Display a listing of the resource.
*
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function index(Article $article)
{
//
}
/**
* Show the form for creating a new resource.
*
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function create(Article $article)
{
//
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Article $article
* @return \Illuminate\Http\Response
*/
public function store(Request $request, Article $article)
{
//
}
/**
* Display the specified resource.
*
* @param \App\Article $article
* @param \App\Comment $comment
* @return \Illuminate\Http\Response
*/
public function show(Article $article, Comment $comment)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Article $article
* @param \App\Comment $comment
* @return \Illuminate\Http\Response
*/
public function edit(Article $article, Comment $comment)
{
//
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param \App\Article $article
* @param \App\Comment $comment
* @return \Illuminate\Http\Response
*/
public function update(Request $request, Article $article, Comment $comment)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param \App\Article $article
* @param \App\Comment $comment
* @return \Illuminate\Http\Response
*/
public function destroy(Article $article, Comment $comment)
{
//
}
}
yes, correct, now try to do it for parents 3 layers deep. like Country State County
It seems like it only supports 1 layer deep.
@fbc Same, would be nice to do it by command, something like --model Order --parents Company,Customer
Please sign in or create an account to participate in this conversation.