I am trying to add a if
condition when resource auto generates.
When I run php artisan make:controller SomeController -r
, I want to generate the following,
class SomeController extends Controller
{
public function index()
{
if (Auth::user()->can('')){
//
}else{
//
}
}
public function create()
{
if (Auth::user()->can('')){
//
}else{
//
}
}
public function store(Request $request)
{
if (Auth::user()->can('')){
//
}else{
//
}
}
public function show($id)
{
if (Auth::user()->can('')){
//
}else{
//
}
}
public function edit($id)
{
if (Auth::user()->can('')){
//
}else{
//
}
}
public function update(Request $request, $id)
{
if (Auth::user()->can('')){
//
}else{
//
}
}
public function destroy($id)
{
if (Auth::user()->can('')){
//
}else{
//
}
}
}
To do the above, go to terminal and
php artisan stub:publish
stubs
directory.controller.stub
according to you need and it's done!When you run php artisan make:controller -r
the next time, it will autogenerate the resource with the changes you made to the stub
file.