1. Go to this page and download the library: Download thehiredgun/formkit library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
...
use App\Models\Eloquent\Book;
use Illuminate\Http\Request;
use TheHiredGun\FormKit\SubmissionKit\SubmissionKit;
...
public function form(Request $request, Book $book = null)
{
// define your rules for the form.
// multi-dimensional array is the preferred style, but you can use an array of strings, as well
$rules = [
'title' => [
'
$form->validate(); // validate the form
$form->setProperties($book); // set the properties on the $book where the values are valid
if ($form->isValid()) {
$book->save();
return redirect()->route('books');
}
}
return view('books.form', [
'book' => $book,
'errors' => $submissionKit->getErrors(),
]);
}
...
public function post(Request $request)
{
$rules = [
'title' => [
'tring',
],
'published_on' => [
'$form->setProperties(new Book()); // set the properties on the $book where the values are valid
if ($form->isValid()) {
$book->save();
return response($book, 201);
}
return response([
'errors' => $submissionKit->getErrors(),
], 400);
}
public function put(Request $request, Book $book)
{
$rules = [
'title' => [
'tring',
],
'published_on' => [
'$form->setProperties($book); // set the properties on the $book where the values are valid
if ($form->isValid()) {
$book->save();
return response(200);
}
return response([
'errors' => $submissionKit->getErrors(),
], 400);
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.