1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00
invoiceninja/app/Console/Commands/stubs/controller.stub

132 lines
3.8 KiB
Plaintext
Raw Normal View History

2016-12-08 14:41:35 +01:00
<?php
namespace $CLASS_NAMESPACE$;
2016-12-08 16:09:45 +01:00
use Auth;
2016-12-08 14:41:35 +01:00
use App\Http\Controllers\BaseController;
2016-12-08 16:09:45 +01:00
use App\Services\DatatableService;
2016-12-08 14:41:35 +01:00
use Modules\$STUDLY_NAME$\Datatables\$STUDLY_NAME$Datatable;
2016-12-09 09:43:20 +01:00
use Modules\$STUDLY_NAME$\Repositories\$STUDLY_NAME$Repository;
2016-12-08 21:51:53 +01:00
use Modules\$STUDLY_NAME$\Http\Requests\$STUDLY_NAME$Request;
use Modules\$STUDLY_NAME$\Http\Requests\Create$STUDLY_NAME$Request;
use Modules\$STUDLY_NAME$\Http\Requests\Update$STUDLY_NAME$Request;
2016-12-08 14:41:35 +01:00
class $CLASS$ extends BaseController
{
2016-12-08 16:09:45 +01:00
protected $$STUDLY_NAME$Repo;
//protected $entityType = '$LOWER_NAME$';
public function __construct($STUDLY_NAME$Repository $$LOWER_NAME$Repo)
{
//parent::__construct();
$this->$LOWER_NAME$Repo = $$LOWER_NAME$Repo;
}
2016-12-08 14:41:35 +01:00
/**
* Display a listing of the resource.
* @return Response
*/
public function index()
{
return view('list_wrapper', [
'entityType' => '$LOWER_NAME$',
'datatable' => new $STUDLY_NAME$Datatable(),
2016-12-09 12:17:04 +01:00
'title' => mtrans('$LOWER_NAME$', '$LOWER_NAME$_list'),
2016-12-08 14:41:35 +01:00
]);
}
2016-12-08 21:39:15 +01:00
public function datatable(DatatableService $datatableService)
2016-12-08 16:09:45 +01:00
{
2017-06-29 14:18:59 +02:00
$search = request()->input('sSearch');
2016-12-08 16:09:45 +01:00
$userId = Auth::user()->filterId();
$datatable = new $STUDLY_NAME$Datatable();
$query = $this->$LOWER_NAME$Repo->find($search, $userId);
return $datatableService->createDatatable($datatable, $query);
}
2016-12-08 14:41:35 +01:00
/**
* Show the form for creating a new resource.
* @return Response
*/
2016-12-08 21:51:53 +01:00
public function create($STUDLY_NAME$Request $request)
2016-12-08 14:41:35 +01:00
{
2016-12-08 20:37:07 +01:00
$data = [
'$LOWER_NAME$' => null,
'method' => 'POST',
'url' => '$LOWER_NAME$',
2016-12-09 12:17:04 +01:00
'title' => mtrans('$LOWER_NAME$', 'new_$LOWER_NAME$'),
2016-12-08 20:37:07 +01:00
];
return view('$LOWER_NAME$::edit', $data);
2016-12-08 14:41:35 +01:00
}
/**
* Store a newly created resource in storage.
* @param Request $request
* @return Response
*/
2016-12-08 21:51:53 +01:00
public function store(Create$STUDLY_NAME$Request $request)
2016-12-08 14:41:35 +01:00
{
2016-12-08 21:39:15 +01:00
$$LOWER_NAME$ = $this->$LOWER_NAME$Repo->save($request->input());
2016-12-08 20:37:07 +01:00
2016-12-08 21:39:15 +01:00
return redirect()->to($$LOWER_NAME$->present()->editUrl)
2016-12-09 12:17:04 +01:00
->with('message', mtrans('$LOWER_NAME$', 'created_$LOWER_NAME$'));
2016-12-08 14:41:35 +01:00
}
/**
* Show the form for editing the specified resource.
* @return Response
*/
2016-12-08 21:39:15 +01:00
public function edit($STUDLY_NAME$Request $request)
{
$$LOWER_NAME$ = $request->entity();
$data = [
'$LOWER_NAME$' => $$LOWER_NAME$,
'method' => 'PUT',
'url' => '$LOWER_NAME$/' . $$LOWER_NAME$->public_id,
2016-12-09 12:17:04 +01:00
'title' => mtrans('$LOWER_NAME$', 'edit_$LOWER_NAME$'),
2016-12-08 21:39:15 +01:00
];
return view('$LOWER_NAME$::edit', $data);
}
/**
* Show the form for editing a resource.
* @return Response
*/
2016-12-08 21:51:53 +01:00
public function show($STUDLY_NAME$Request $request)
2016-12-08 14:41:35 +01:00
{
2016-12-08 21:39:15 +01:00
return redirect()->to("$LOWER_NAME$/{$request->$LOWER_NAME$}/edit");
2016-12-08 14:41:35 +01:00
}
/**
* Update the specified resource in storage.
* @param Request $request
* @return Response
*/
2016-12-08 21:51:53 +01:00
public function update(Update$STUDLY_NAME$Request $request)
2016-12-08 14:41:35 +01:00
{
2016-12-08 21:51:53 +01:00
$$LOWER_NAME$ = $this->$LOWER_NAME$Repo->save($request->input(), $request->entity());
return redirect()->to($$LOWER_NAME$->present()->editUrl)
2016-12-09 12:17:04 +01:00
->with('message', mtrans('$LOWER_NAME$', 'updated_$LOWER_NAME$'));
2016-12-08 14:41:35 +01:00
}
2016-12-08 23:34:24 +01:00
/**
* Update multiple resources
*/
public function bulk()
{
$action = request()->input('action');
$ids = request()->input('public_id') ?: request()->input('ids');
$count = $this->$LOWER_NAME$Repo->bulk($ids, $action);
return redirect()->to('$LOWER_NAME$')
2016-12-09 12:17:04 +01:00
->with('message', mtrans('$LOWER_NAME$', $action . '_$LOWER_NAME$_complete'));
2016-12-08 23:34:24 +01:00
}
2016-12-08 14:41:35 +01:00
}