almost there... problem with update button
This commit is contained in:
parent
080d196138
commit
c28936fefb
2 changed files with 133 additions and 65 deletions
|
@ -4,37 +4,80 @@ namespace App\Http\Livewire;
|
||||||
|
|
||||||
use Laravel\Passport\Client;
|
use Laravel\Passport\Client;
|
||||||
use Laravel\Passport\ClientRepository;
|
use Laravel\Passport\ClientRepository;
|
||||||
|
use Laravel\Passport\Passport;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
|
||||||
class OauthClients extends Component
|
class OauthClients extends Component
|
||||||
{
|
{
|
||||||
|
public $name;
|
||||||
|
public $redirect;
|
||||||
|
public $editClientId;
|
||||||
|
public $editName;
|
||||||
|
public $editRedirect;
|
||||||
|
|
||||||
|
protected $clientRepository;
|
||||||
|
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->clientRepository = app(ClientRepository::class);
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
public function render()
|
public function render()
|
||||||
{
|
{
|
||||||
return view('livewire.oauth-clients', [
|
return view('livewire.oauth-clients', [
|
||||||
'clients' => app(ClientRepository::class)->activeForUser(auth()->user()->id),
|
'clients' => $this->clientRepository->activeForUser(auth()->user()->id),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rules(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'name' => 'required|string|max:255',
|
|
||||||
'redirect' => 'required|url|max:255',
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createClient(): void
|
public function createClient(): void
|
||||||
{
|
{
|
||||||
$this->validate();
|
$this->validate([
|
||||||
|
'name' => 'required|string|max:255',
|
||||||
|
'redirect' => 'required|url|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
//$newClient = ;
|
$newClient = $this->clientRepository->create(
|
||||||
|
auth()->user()->id,
|
||||||
|
$this->name,
|
||||||
|
$this->redirect,
|
||||||
|
);
|
||||||
|
|
||||||
//$this->dispatchBrowserEvent('clientCreated', $newClient->accessToken);
|
$this->dispatchBrowserEvent('clientCreated');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function deleteClient(Client $clientId): void
|
public function deleteClient(Client $clientId): void
|
||||||
{
|
{
|
||||||
//->delete must be of type Client - thus the model binding
|
// test for safety
|
||||||
app(ClientRepository::class)->delete($clientId);
|
// ->delete must be of type Client - thus the model binding
|
||||||
|
$this->clientRepository->delete($clientId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function editClient(Client $editClientId): void
|
||||||
|
{
|
||||||
|
$this->editName = $editClientId->name;
|
||||||
|
$this->editRedirect = $editClientId->redirect;
|
||||||
|
|
||||||
|
$this->dispatchBrowserEvent('editClient');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateClient(Client $editClientId): void
|
||||||
|
{
|
||||||
|
$this->validate([
|
||||||
|
'editName' => 'required|string|max:255',
|
||||||
|
'editRedirect' => 'required|url|max:255',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$client = $this->clientRepository->find($editClientId->id);
|
||||||
|
if ($client->user_id == auth()->user()->id) {
|
||||||
|
$client->name = $this->editName;
|
||||||
|
$client->redirect = $this->editRedirect;
|
||||||
|
$client->save();
|
||||||
|
} else {
|
||||||
|
// throw error
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dispatchBrowserEvent('clientUpdated');
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
(Livewire) OAuth Clients
|
(Livewire) OAuth Clients
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<a class="action-link"
|
<a class="button button-small"
|
||||||
{{-- @click="showCreateClientForm"--}}
|
wire:click="$emit('openModal')"
|
||||||
>
|
>
|
||||||
Create New Client
|
Create New Client
|
||||||
</a>
|
</a>
|
||||||
|
@ -55,7 +55,7 @@
|
||||||
<!-- Edit Button -->
|
<!-- Edit Button -->
|
||||||
<td style="vertical-align: middle;">
|
<td style="vertical-align: middle;">
|
||||||
<a class="action-link"
|
<a class="action-link"
|
||||||
@click="edit(client)"
|
wire:click="editClient('{{ $client->id }}')"
|
||||||
>
|
>
|
||||||
Edit
|
Edit
|
||||||
</a>
|
</a>
|
||||||
|
@ -76,7 +76,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Create Client Modal -->
|
<!-- Create Client Modal -->
|
||||||
<div class="modal fade" id="modal-create-client" tabindex="-1" role="dialog">
|
<div class="modal fade" id="modal-create-client" tabindex="-1" role="dialog" wire:ignore.self>
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
@ -89,19 +89,20 @@
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<!-- Form Errors -->
|
<!-- Form Errors -->
|
||||||
<div class="alert alert-danger"
|
@if($errors->has('name') || $errors->has('redirect'))
|
||||||
{{-- v-if="createForm.errors.length > 0"--}}
|
<div class="alert alert-danger">
|
||||||
>
|
|
||||||
<p><strong>Whoops!</strong> Something went wrong!</p>
|
<p><strong>Whoops!</strong> Something went wrong!</p>
|
||||||
<br>
|
<br>
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
@if($errors->has('name'))
|
||||||
{{-- v-for="error in createForm.errors"--}}
|
<li>{{ $errors->first('name') }}</li>
|
||||||
>
|
@endif
|
||||||
{{-- {{ error }}--}}
|
@if($errors->has('redirect'))
|
||||||
</li>
|
<li>{{ $errors->first('redirect') }}</li>
|
||||||
|
@endif
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<!-- Create Client Form -->
|
<!-- Create Client Form -->
|
||||||
<form class="form-horizontal" role="form">
|
<form class="form-horizontal" role="form">
|
||||||
|
@ -110,9 +111,11 @@
|
||||||
<label class="col-md-3 control-label" for="create-client-name">Name</label>
|
<label class="col-md-3 control-label" for="create-client-name">Name</label>
|
||||||
|
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<input id="create-client-name" type="text" aria-label="create-client-name" class="form-control"
|
<input id="create-client-name"
|
||||||
{{-- @keyup.enter="store" --}}
|
type="text"
|
||||||
{{-- v-model="createForm.name"--}}
|
aria-label="create-client-name"
|
||||||
|
class="form-control"
|
||||||
|
wire:model="name"
|
||||||
>
|
>
|
||||||
|
|
||||||
<span class="help-block">
|
<span class="help-block">
|
||||||
|
@ -126,9 +129,11 @@
|
||||||
<label class="col-md-3 control-label" for="redirect">Redirect URL</label>
|
<label class="col-md-3 control-label" for="redirect">Redirect URL</label>
|
||||||
|
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<input type="text" class="form-control" aria-label="redirect" name="redirect"
|
<input type="text"
|
||||||
{{-- @keyup.enter="store" --}}
|
class="form-control"
|
||||||
{{-- v-model="createForm.redirect"--}}
|
aria-label="redirect"
|
||||||
|
name="redirect"
|
||||||
|
wire:model="redirect"
|
||||||
>
|
>
|
||||||
|
|
||||||
<span class="help-block">
|
<span class="help-block">
|
||||||
|
@ -142,9 +147,9 @@
|
||||||
<!-- Modal Actions -->
|
<!-- Modal Actions -->
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||||
|
<button type="button"
|
||||||
<button type="button" class="btn btn-primary"
|
class="btn btn-primary"
|
||||||
{{-- @click="store"--}}
|
wire:click="createClient"
|
||||||
>
|
>
|
||||||
Create
|
Create
|
||||||
</button>
|
</button>
|
||||||
|
@ -154,7 +159,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Edit Client Modal -->
|
<!-- Edit Client Modal -->
|
||||||
<div class="modal fade" id="modal-edit-client" tabindex="-1" role="dialog">
|
<div class="modal fade" id="modal-edit-client" tabindex="-1" role="dialog" wire:ignore.self>
|
||||||
<div class="modal-dialog">
|
<div class="modal-dialog">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-header">
|
<div class="modal-header">
|
||||||
|
@ -165,32 +170,36 @@
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<!-- Form Errors -->
|
@if($errors->has('newName') || $errors->has('newRedirect'))
|
||||||
<div class="alert alert-danger"
|
<div class="alert alert-danger">
|
||||||
{{-- v-if="editForm.errors.length > 0"--}}
|
|
||||||
>
|
|
||||||
<p><strong>Whoops!</strong> Something went wrong!</p>
|
<p><strong>Whoops!</strong> Something went wrong!</p>
|
||||||
<br>
|
<br>
|
||||||
<ul>
|
<ul>
|
||||||
<li
|
@if($errors->has('newName'))
|
||||||
{{-- v-for="error in editForm.errors"--}}
|
<li>{{ $errors->first('newName') }}</li>
|
||||||
>
|
@endif
|
||||||
{{-- {{ error }}--}}
|
@if($errors->has('newRedirect'))
|
||||||
</li>
|
<li>{{ $errors->first('newRedirect') }}</li>
|
||||||
|
@endif
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@endif
|
||||||
|
|
||||||
<!-- Edit Client Form -->
|
<!-- Edit Client Form -->
|
||||||
<form class="form-horizontal" role="form">
|
<form class="form-horizontal">
|
||||||
<!-- Name -->
|
<!-- Name -->
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label class="col-md-3 control-label" for="edit-client-name">Name</label>
|
<label class="col-md-3 control-label" for="edit-client-name">Name</label>
|
||||||
|
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<input id="edit-client-name" type="text" aria-label="edit-client-name" class="form-control"
|
<input
|
||||||
{{-- @keyup.enter="update" --}}
|
id="edit-client-name"
|
||||||
{{-- v-model="editForm.name"--}}
|
type="text"
|
||||||
|
aria-label="edit-client-name"
|
||||||
|
class="form-control"
|
||||||
|
wire:model="editName"
|
||||||
>
|
>
|
||||||
|
|
||||||
<span class="help-block">
|
<span class="help-block">
|
||||||
|
@ -204,9 +213,12 @@
|
||||||
<label class="col-md-3 control-label" for="redirect">Redirect URL</label>
|
<label class="col-md-3 control-label" for="redirect">Redirect URL</label>
|
||||||
|
|
||||||
<div class="col-md-7">
|
<div class="col-md-7">
|
||||||
<input type="text" class="form-control" name="redirect" aria-label="redirect"
|
<input
|
||||||
{{-- @keyup.enter="update" --}}
|
type="text"
|
||||||
{{-- v-model="editForm.redirect"--}}
|
class="form-control"
|
||||||
|
name="redirect"
|
||||||
|
aria-label="redirect"
|
||||||
|
wire:model="editRedirect"
|
||||||
>
|
>
|
||||||
|
|
||||||
<span class="help-block">
|
<span class="help-block">
|
||||||
|
@ -221,16 +233,29 @@
|
||||||
<div class="modal-footer">
|
<div class="modal-footer">
|
||||||
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
|
||||||
|
|
||||||
<button type="button" class="btn btn-primary"
|
<button type="button"
|
||||||
{{-- @click="update"--}}
|
class="btn btn-primary"
|
||||||
|
wire:click="updateClient('{{ $editClientId }}')"
|
||||||
>
|
>
|
||||||
Save Changes
|
Update Client
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<script>
|
<script>
|
||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
window.livewire.on('openModal', () => {
|
||||||
|
$('#modal-create-client').modal('show');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
window.addEventListener('clientCreated', event => {
|
||||||
|
$('#modal-create-client').modal('hide');
|
||||||
|
});
|
||||||
|
window.addEventListener('editClient', event => {
|
||||||
|
$('#modal-edit-client').modal('show');
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
Loading…
Add table
Reference in a new issue