1. Go to this page and download the library: Download ghebby/laravel-hfm 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/ */
namespace App\Models;
class Company extends Model
{
protected $table = 'companies';
protected $fillable = ['name', 'fiscal_code', '...'];
// OR
protected $guarded = ['id'];
}
namespace App\Http\Controllers;
class CompanyController extends Controller
{
// [...]
public function create(Request $request)
{
//
return view('company.create');
}
public function store(Request $request)
{
// before persisting the data n DB you must validate it.
// thus writing validation rules is a mandatory action
// and it might look like this.
$validaData = $request->validate(
[
'name' => 'string|max:255|pdate(Request $request, $id)
{
// before persisting the data n DB you must validate it.
// thus writing validation rules is a mandatory action
// and it might look like this.
$validaData = $request->validate(
[
'name' => 'string|max:255|
namespace App\Http\Controllers;
class CompanyController extends Controller
{
// [...]
public function create(Request $request)
{
//
$fields = Company::getFieldsMap();
if( isset($fields['id']) ){
// when creating a new entry, id field in ld map,
// which nakes it very easy to override or integrate rules, example
// $rules['fiscal_code'][] = 'min:10'; // addd a constraint for min number of char
// unset($rules['email']); // this will prevent the validator method to set the key value pair for 'email' in $validaData
$validaData = $request->validate($rules);
Company::create($validaData);
return redirect()->route('company.index');
}
public function edit(Request $request, $id)
{
//
$company = Company::findOrFail($id);
$fields = Company::getFieldsMap();
return view('company.edit')->with('company', $company)->with('fields', $fields);
}
public function update(Request $request, $id)
{
$rules = Company::getDefaultValidationRules();
$validaData = $request->validate($rules);
$company = Company::findOrFail($id);
$company->update($validaData);
return redirect()->route('company.index');
}
// [...]
}
//[....]
<form method="POST" action="{ route('company.store') }" >
@csrf
<div>
@if( count($fileds) > 0 )
// if you have published and customized the UI helper functions, use this
@rm>
//[....]
//[....]
<form method="POST" action="{ route('company.edit', $company->id) }" >
@csrf
<div>
@if( count($fileds) > 0 )
// if you have published and customized the UI helper functions, use this
@submit">Save</button>
</form>
//[....]