Make your database columns available in your blade view effortlessly.
You can install the package via composer:
composer require bnhashem/form-data- Incredibly easy to use.
- Help use signle form for create and update.
- The values name are the same as the database columns name, save you calling
oldconditionally in the view.
use Bnhashem\FormData\FormData;
$formData = new FormData();use Bnhashem\FormData\FormData;
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('your.custom.view', FormData::old(new Model()));
}use Bnhashem\FormData\FormData;
/**
* Show the form for editing the specified resource.
*
* @param \App\Models\Model $model
* @return \Illuminate\Http\Response
*/
public function edit(Model $model)
{
return view('your.custom.view', FormData::edit($model);
}/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('content');
$table->timestamps();
});
}use Bnhashem\FormData\FormData;
public function create()
{
return view('your.custom.view', FormData::old(new Post()));
}Mind that the name of variable must be the same as the column name value in the database
<div class="form-group col-6">
<label>{{ __('Name') }}</label>
<input type="text" name="name" value="{{ $name }}">
@error('name') <span class="erorr">{{ $message }}</span> @enderror
</div>use Bnhashem\FormData\FormData;
public function edit(Post $post)
{
return view('your.custom.view', FormData::edit($post));
}<div class="form-group col-6">
<label>{{ __('Name') }}</label>
<input type="text" name="name" value="{{ $name }}">
@error('name') <span class="erorr">{{ $message }}</span> @enderror
</div>Somtimes Column have many values and unique keys, in this case We will do the following:
public function up()
{
Schema::create('posts', function (Blueprint $table) {
$table->id();
$table->json('name');
$table->json('content');
});
}Add static property $JSONCOLUMNS, with column names and the the keys that you want to add in the blade.
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
public static $JSONCOLUMNS = [
'name' => ['en', 'ar'],
'content' => ['ar', 'en']
];
}<div class="form-group col-6">
<label>{{ __('English Name') }}</label>
<input type="text" name="name['en']" value="{{ $name['en'] }}">
@error('name.en') <span class="erorr">{{ $message }}</span> @enderror
</div>
<div class="form-group col-6">
<label>{{ __('Arabic Name') }}</label>
<input type="text" name="name['ar']" value="{{ $name['ar'] }}">
@error('name.ar') <span class="erorr">{{ $message }}</span> @enderror
</div>Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
Please review our security policy on how to report security vulnerabilities.
The MIT License (MIT). Please see License File for more information.