-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Create method update() on user UpdateRequest class - Modify feature tests - Create branch module on master page (WIP)
- Loading branch information
Showing
19 changed files
with
541 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Branch; | ||
|
||
use App\Infrastructure\Foundation\Http\FormRequest; | ||
|
||
abstract class AbstractRequest extends FormRequest | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function authorize() | ||
{ | ||
return !is_null($this->user()); | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function attributes() | ||
{ | ||
return [ | ||
'name' => trans('Name'), | ||
'address' => trans('Address'), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Branch; | ||
|
||
use App\Models\Branch; | ||
use App\Models\Role; | ||
use Illuminate\Validation\Rule; | ||
use Illuminate\Validation\Rules; | ||
|
||
class StoreRequest extends AbstractRequest | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|string|max:255', | ||
'address' => 'required|string', | ||
]; | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @return \App\Models\Branch | ||
*/ | ||
public function store(): Branch | ||
{ | ||
/** @var \App\Models\Branch $branch */ | ||
$branch = Branch::make($this->validated()); | ||
|
||
$branch->save(); | ||
|
||
return $branch; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests\Branch; | ||
|
||
use App\Models\Branch; | ||
|
||
class UpdateRequest extends AbstractRequest | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'name' => 'required|string|max:255', | ||
'address' => 'required|string', | ||
]; | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \App\Models\Branch $branch | ||
* @return \App\Models\Branch | ||
*/ | ||
public function update(Branch $branch): Branch | ||
{ | ||
$branch->update($this->validated()); | ||
|
||
return $branch; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
namespace App\Http\Resources\DataTables; | ||
|
||
use Illuminate\Http\Resources\Json\JsonResource; | ||
|
||
/** | ||
* @property \App\Models\Branch $resource | ||
*/ | ||
class BranchResource extends JsonResource | ||
{ | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function toArray($request) | ||
{ | ||
$elements = []; | ||
|
||
if ($request->user()->can('view', $this->resource)) { | ||
$elements[] = view('components.datatables.link-show', [ | ||
'url' => route('master.branch.show', $this->resource), | ||
])->render(); | ||
} | ||
|
||
if ($request->user()->can('update', $this->resource)) { | ||
$elements[] = view('components.datatables.link-edit', [ | ||
'url' => route('master.branch.edit', $this->resource), | ||
])->render(); | ||
} | ||
|
||
if ($request->user()->can('delete', $this->resource)) { | ||
$elements[] = view('components.datatables.link-destroy', [ | ||
'url' => route('master.branch.destroy', $this->resource), | ||
])->render(); | ||
} | ||
|
||
return [ | ||
'checkbox' => view('components.datatables.checkbox', [ | ||
'value' => $this->resource->getKey(), | ||
])->render(), | ||
'name' => $this->resource->name, | ||
'address' => $this->resource->address, | ||
'action' => view('components.datatables.button-group', compact('elements'))->render(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php | ||
|
||
namespace App\Policies; | ||
|
||
use App\Models\Branch; | ||
use App\Models\Role; | ||
use App\Models\User; | ||
use Illuminate\Auth\Access\HandlesAuthorization; | ||
|
||
class BranchPolicy | ||
{ | ||
use HandlesAuthorization; | ||
|
||
/** | ||
* Perform pre-authorization checks. | ||
* | ||
* @param \App\Models\User $user | ||
* @param string $ability | ||
* @return void|bool | ||
*/ | ||
public function before(User $user, $ability) | ||
{ | ||
if ($user->hasRole(Role::ROLE_ADMIN)) { | ||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Determine whether the user can view any models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function viewAny(User $user) | ||
{ | ||
return $user->hasRole(Role::ROLE_STAFF); | ||
} | ||
|
||
/** | ||
* Determine whether the user can view the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Branch $branch | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function view(User $user, Branch $branch) | ||
{ | ||
return $user->branch->is($branch); | ||
} | ||
|
||
/** | ||
* Determine whether the user can create models. | ||
* | ||
* @param \App\Models\User $user | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function create(User $user) | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Determine whether the user can update the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Branch $branch | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function update(User $user, Branch $branch) | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Determine whether the user can delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Branch $branch | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function delete(User $user, Branch $branch) | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Determine whether the user can restore the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Branch $branch | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function restore(User $user, Branch $branch) | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* Determine whether the user can permanently delete the model. | ||
* | ||
* @param \App\Models\User $user | ||
* @param \App\Models\Branch $branch | ||
* @return \Illuminate\Auth\Access\Response|bool | ||
*/ | ||
public function forceDelete(User $user, Branch $branch) | ||
{ | ||
return false; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.