The dnj/laravel-simple-contact-form Public package provides easy way to manage contact of your app. The Package stores all data in the contacts table.
- Latest versions of PHP and PHPUnit and PHPCsFixer
- Best practices applied:
README.md
(badges included)LICENSE
composer.json
phpunit.xml
.gitignore
.php-cs-fixer.php
openAPI
- Some useful resources to start coding
You can install the package via composer:
composer require dnj/laravel-simple-contact-form
The package will automatically register itself.
After this you can create the contacts
table by running the migrations:
php artisan migrate
You can optionally publish the config file with:
php artisan vendor:publish --provider="dnj\SimpleContactForm\SimpleContactFormServiceProvider" --tag="config"
[
// If set True we will access to route api else we will not access
'route_enable' => true,
// To set the prefix for route api
'route_prefix' => 'api',
]
To use and management CRUD contact package, the first thing you need to do is creating an object of then ContactManager class. which is accessed in the name space below.
use dnj\SimpleContactForm\ContactManager;
$contactManager = new ContactManager();
To create a contact, you can use the store function in the ContactManager class. This function includes parameters that include:
- userIp : It is to save the IP address of the client who wants to register a contact. To get the client's IP, we use the current
\request()->ip()
command. - contactChannels: It is for saving the type of contact. which is an array. This array contains a key. for example:
array('mobile') or array('email') or etc
- message: It is for saving contact text.
- additionalDetails: This parameter is used to save more information. which is in the form of an array. for example:
array('priority' => 'high')
<?php
use dnj\SimpleContactForm\ContactManager;
$contactManager = new ContactManager();
$data = [
'userIp' => '127.0.0.1',
'contactChannels' => array ('email'),
'message' => 'this is a first contact',
'additionalDetails' => array('priority' => 'high')
];
$contactManager->store($data['userIp'],
$data['contactChannels'],
$data['message'],
$data['additionalDetails']
);
To update a contact, you can use the update function in the ContactManager class. This function includes two parameters that include
- contactId : ID of the contact we want to edit
- changes: This parameter, which is in the form of an array, contains the information that we want to edit a specific contact.
<?php
use dnj\SimpleContactForm\ContactManager;
use dnj\SimpleContactForm\Models\Contact;
$contactManager = new ContactManager();
$data = [
'userIp' => '127.0.0.1',
'contactChannels' => array ('email'),
'message' => 'this is a first contact',
'additionalDetails' => array('priority' => 'high')
];
$contact = Contact::query()
->findOrFail(1);
$contactManager->update($contact->id, $data);
The return value type of the function is store and update of contact model type.
name | Method | route name | path | Description |
---|---|---|---|---|
Index | GET | contacts.index |
/contacts/{contacts} |
Display a specific contact |
Store | POST | contacts.store |
/contacts |
Store a contact |
Update | PUT | contacts.update |
/contacts/{contacts} |
Update a specific contact |
Destroy | Delete | contacts.destroy |
/contacts/{contacts} |
Destroy a specific contact |
-
In order to edit and delete a contact, the user needs to be
authenticated
beforehand, otherwise she will be faced with an errorunauthenticated
. -
In the
config/contact.php
file, you can define a desired prefix for your route api by giving aroute_prefix
value. for exampleroute_prefix: 'api'
.
A document in YAML format has been prepared for better familiarization and use of package web services. which is placed in the docs
folder.
To use this file, you can import it on the stoplight.io site and see all available web services.
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
./vendor/bin/phpunit
We'll try to maintain this project as simple as possible, but Pull Requests are welcomed!
The MIT License (MIT). Please see License File for more information.