andersao / andersao/l5-repository

Is it a BUG? The command:php artisan make:entity generates file error!

未關閉
#382 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
PHP
星號
4.2k
分支
880
PR 合併指標
30 天內沒有已合併 PR

描述

Version: "prettus/l5-repository": "^2.6"
```php
Would you like to create a Presenter? [y|N] (yes/no) [no]:
> N

Would you like to create a Validator? [y|N] (yes/no) [no]:
> N

Would you like to create a Controller? [y|N] (yes/no) [no]:
> y
```
Please notice that: Would you like to create a Validator? I choose the N, but the the generated files contains the Validator code.

For example:
```php
repository = $repository;
$this->validator = $validator;
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$this->repository->pushCriteria(app('Prettus\Repository\Criteria\RequestCriteria'));
$post1s = $this->repository->all();

if (request()->wantsJson()) {

return response()->json([
'data' => $post1s,
]);
}

return view('post1s.index', compact('post1s'));
}

/**
* Store a newly created resource in storage.
*
* @param Post1CreateRequest $request
*
* @return \Illuminate\Http\Response
*/
public function store(Post1CreateRequest $request)
{

try {

$this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_CREATE);

$post1 = $this->repository->create($request->all());

$response = [
'message' => 'Post1 created.',
'data' => $post1->toArray(),
];

if ($request->wantsJson()) {

return response()->json($response);
}

return redirect()->back()->with('message', $response['message']);
} catch (ValidatorException $e) {
if ($request->wantsJson()) {
return response()->json([
'error' => true,
'message' => $e->getMessageBag()
]);
}

return redirect()->back()->withErrors($e->getMessageBag())->withInput();
}
}

/**
* Display the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function show($id)
{
$post1 = $this->repository->find($id);

if (request()->wantsJson()) {

return response()->json([
'data' => $post1,
]);
}

return view('post1s.show', compact('post1'));
}

/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function edit($id)
{

$post1 = $this->repository->find($id);

return view('post1s.edit', compact('post1'));
}

/**
* Update the specified resource in storage.
*
* @param Post1UpdateRequest $request
* @param string $id
*
* @return Response
*/
public function update(Post1UpdateRequest $request, $id)
{

try {

$this->validator->with($request->all())->passesOrFail(ValidatorInterface::RULE_UPDATE);

$post1 = $this->repository->update($request->all(), $id);

$response = [
'message' => 'Post1 updated.',
'data' => $post1->toArray(),
];

if ($request->wantsJson()) {

return response()->json($response);
}

return redirect()->back()->with('message', $response['message']);
} catch (ValidatorException $e) {

if ($request->wantsJson()) {

return response()->json([
'error' => true,
'message' => $e->getMessageBag()
]);
}

return redirect()->back()->withErrors($e->getMessageBag())->withInput();
}
}

/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$deleted = $this->repository->delete($id);

if (request()->wantsJson()) {

return response()->json([
'message' => 'Post1 deleted.',
'deleted' => $deleted,
]);
}

return redirect()->back()->with('message', 'Post1 deleted.');
}
}

```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。