666 |
user Details
667 |
name: {{ $user ->name }}
668 |
email: {{ $user ->email }}
669 |
email_verified_at: {{ $user ->email_verified_at }}
670 |
password: {{ $user ->password }}
671 |
remember_token: {{ $user ->remember_token }}
672 |
673 |
674 | ```
675 |
676 | - CURL (if applicable):
677 | - You will find it in the laravel-auto-crud folder under the name curl.txt.
678 | ```bash
679 | =====================User=====================
680 | curl --location 'http://127.0.0.1:8000/api/users' \
681 | --header 'Accept: application/json' \
682 | --header 'Content-Type: application/json' \
683 | --request POST \
684 | --data '{
685 | "name": "value",
686 | "email": "value",
687 | "email_verified_at": "value",
688 | "password": "value",
689 | "remember_token": "value"
690 | }'
691 |
692 | curl --location 'http://127.0.0.1:8000/api/users/:id' \
693 | --header 'Accept: application/json' \
694 | --header 'Content-Type: application/json' \
695 | --request PATCH \
696 | --data '{
697 | "name": "value",
698 | "email": "value",
699 | "email_verified_at": "value",
700 | "password": "value",
701 | "remember_token": "value"
702 | }'
703 |
704 | curl --location 'http://127.0.0.1:8000/api/users/:id' \
705 | --header 'Accept: application/json' \
706 | --header 'Content-Type: application/json' \
707 | --request DELETE
708 |
709 | curl --location 'http://127.0.0.1:8000/api/users' \
710 | --header 'Accept: application/json' \
711 | --header 'Content-Type: application/json' \
712 | --request GET
713 |
714 | curl --location 'http://127.0.0.1:8000/api/users/:id' \
715 | --header 'Accept: application/json' \
716 | --header 'Content-Type: application/json' \
717 | --request GET
718 |
719 | =====================User=====================
720 | ```
721 | - Postman Collection (if applicable):
722 | - You will find it in the laravel-auto-crud folder under the name postman.json.
723 | - Swagger API V3 Collection (if applicable):
724 | - You will find it in the laravel-auto-crud folder under the name swagger-api.json.
725 | - Repository (if applicable):
726 | ```php
727 | user = $user;
747 | }
748 |
749 | /**
750 | * Get all user.
751 | *
752 | * @return User $user
753 | */
754 | public function all()
755 | {
756 | return $this->user->get();
757 | }
758 |
759 | /**
760 | * Get user by id
761 | *
762 | * @param $id
763 | * @return mixed
764 | */
765 | public function getById(int $id)
766 | {
767 | return $this->user->find($id);
768 | }
769 |
770 | /**
771 | * Save User
772 | *
773 | * @param $data
774 | * @return User
775 | */
776 | public function save(array $data)
777 | {
778 | return User::create($data);
779 | }
780 |
781 | /**
782 | * Update User
783 | *
784 | * @param $data
785 | * @return User
786 | */
787 | public function update(array $data, int $id)
788 | {
789 | $user = $this->user->find($id);
790 | $user->update($data);
791 | return $user;
792 | }
793 |
794 | /**
795 | * Delete User
796 | *
797 | * @param $data
798 | * @return User
799 | */
800 | public function delete(int $id)
801 | {
802 | $user = $this->user->find($id);
803 | $user->delete();
804 | return $user;
805 | }
806 | }
807 | ```
808 |
809 | - Service (if applicable):
810 | ```php
811 | userRepository = $userRepository;
835 | }
836 |
837 | /**
838 | * Get all userRepository.
839 | *
840 | * @return String
841 | */
842 | public function getAll()
843 | {
844 | return $this->userRepository->all();
845 | }
846 |
847 | /**
848 | * Get userRepository by id.
849 | *
850 | * @param $id
851 | * @return String
852 | */
853 | public function getById(int $id)
854 | {
855 | return $this->userRepository->getById($id);
856 | }
857 |
858 | /**
859 | * Validate userRepository data.
860 | * Store to DB if there are no errors.
861 | *
862 | * @param array $data
863 | * @return String
864 | */
865 | public function save(array $data)
866 | {
867 | return $this->userRepository->save($data);
868 | }
869 |
870 | /**
871 | * Update userRepository data
872 | * Store to DB if there are no errors.
873 | *
874 | * @param array $data
875 | * @return String
876 | */
877 | public function update(array $data, int $id)
878 | {
879 | DB::beginTransaction();
880 | try {
881 | $userRepository = $this->userRepository->update($data, $id);
882 | DB::commit();
883 | return $userRepository;
884 | } catch (Exception $e) {
885 | DB::rollBack();
886 | report($e);
887 | throw new InvalidArgumentException('Unable to update post data');
888 | }
889 | }
890 |
891 | /**
892 | * Delete userRepository by id.
893 | *
894 | * @param $id
895 | * @return String
896 | */
897 | public function deleteById(int $id)
898 | {
899 | DB::beginTransaction();
900 | try {
901 | $userRepository = $this->userRepository->delete($id);
902 | DB::commit();
903 | return $userRepository;
904 | } catch (Exception $e) {
905 | DB::rollBack();
906 | report($e);
907 | throw new InvalidArgumentException('Unable to delete post data');
908 | }
909 | }
910 |
911 | }
912 | ```
913 | - Spatie Data (if applicable):
914 | ```php
915 |