From 46764b2e1b67d4cb0ae590a30664426ef512ca77 Mon Sep 17 00:00:00 2001 From: Jonathan Reinink Date: Mon, 15 Apr 2019 21:18:29 -0400 Subject: [PATCH] Update all pages to use Inertia for POST, PUT and DELETE requests --- app/Http/Controllers/ContactsController.php | 13 ++++- .../Controllers/OrganizationsController.php | 1 - app/Http/Controllers/UsersController.php | 13 ++++- resources/js/Pages/Auth/Login.vue | 2 +- resources/js/Pages/Contacts/Create.vue | 49 ++++++++++------- resources/js/Pages/Contacts/Edit.vue | 53 +++++++++---------- resources/js/Pages/Organizations/Create.vue | 19 +++---- resources/js/Pages/Organizations/Edit.vue | 21 ++++---- resources/js/Pages/Users/Create.vue | 50 ++++++++++------- resources/js/Pages/Users/Edit.vue | 44 +++++++-------- resources/js/Shared/SelectInput.vue | 9 ++-- resources/js/Shared/TextInput.vue | 9 ++-- resources/js/Shared/TextareaInput.vue | 14 +++-- resources/js/Utils/Form.js | 44 --------------- 14 files changed, 174 insertions(+), 167 deletions(-) delete mode 100644 resources/js/Utils/Form.js diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php index 835dfc8..2083752 100644 --- a/app/Http/Controllers/ContactsController.php +++ b/app/Http/Controllers/ContactsController.php @@ -7,6 +7,7 @@ use Inertia\Inertia; use Illuminate\Validation\Rule; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Request; +use Illuminate\Support\Facades\Redirect; class ContactsController extends Controller { @@ -46,7 +47,7 @@ class ContactsController extends Controller public function store() { - return Auth::user()->account->contacts()->create( + Auth::user()->account->contacts()->create( Request::validate([ 'first_name' => ['required', 'max:50'], 'last_name' => ['required', 'max:50'], @@ -61,7 +62,9 @@ class ContactsController extends Controller 'country' => ['nullable', 'max:2'], 'postal_code' => ['nullable', 'max:25'], ]) - )->only('id'); + ); + + return Redirect::route('contacts'); } public function edit(Contact $contact) @@ -107,15 +110,21 @@ class ContactsController extends Controller 'postal_code' => ['nullable', 'max:25'], ]) ); + + return Redirect::route('contacts.edit', $contact); } public function destroy(Contact $contact) { $contact->delete(); + + return Redirect::route('contacts.edit', $contact); } public function restore(Contact $contact) { $contact->restore(); + + return Redirect::route('contacts.edit', $contact); } } diff --git a/app/Http/Controllers/OrganizationsController.php b/app/Http/Controllers/OrganizationsController.php index 9129d1e..45b5df2 100644 --- a/app/Http/Controllers/OrganizationsController.php +++ b/app/Http/Controllers/OrganizationsController.php @@ -6,7 +6,6 @@ use Inertia\Inertia; use App\Organization; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Request; -use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Redirect; class OrganizationsController extends Controller diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 0951b96..a5afc0a 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -7,6 +7,7 @@ use Inertia\Inertia; use Illuminate\Validation\Rule; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Request; +use Illuminate\Support\Facades\Redirect; class UsersController extends Controller { @@ -37,7 +38,7 @@ class UsersController extends Controller public function store() { - return Auth::user()->account->users()->create( + Auth::user()->account->users()->create( Request::validate([ 'first_name' => ['required', 'max:50'], 'last_name' => ['required', 'max:50'], @@ -45,7 +46,9 @@ class UsersController extends Controller 'password' => ['nullable'], 'owner' => ['required', 'boolean'], ]) - )->only('id'); + ); + + return Redirect::route('users'); } public function edit(User $user) @@ -77,15 +80,21 @@ class UsersController extends Controller if (Request::get('password')) { $user->update(['password' => Request::get('password')]); } + + return Redirect::route('users.edit', $user); } public function destroy(User $user) { $user->delete(); + + return Redirect::route('users.edit', $user); } public function restore(User $user) { $user->restore(); + + return Redirect::route('users.edit', $user); } } diff --git a/resources/js/Pages/Auth/Login.vue b/resources/js/Pages/Auth/Login.vue index aa7ee4f..cd3e62e 100644 --- a/resources/js/Pages/Auth/Login.vue +++ b/resources/js/Pages/Auth/Login.vue @@ -6,7 +6,7 @@

Welcome Back!

- +