Created
December 30, 2015 19:27
-
-
Save noxify/136b486acf46355e22d7 to your computer and use it in GitHub Desktop.
SoaS - Not working example with ajax form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
Admin::model('App\Entities\Company2')->translate(true)->title('Translatable Companies')->display(function () | |
{ | |
$display = AdminDisplay::table(); | |
$display->with('translations'); | |
$display->columns([ | |
Column::string('title')->label('Title'), | |
Column::string('companyName')->label('Company Name'), | |
Column::string('address')->label('Address'), | |
]); | |
return $display; | |
})->edit(function ($id) | |
{ | |
$form = AdminForm::form(); | |
$form->ajax_validation(true); | |
$form->items([ | |
FormItem::hidden('contact_id'), | |
FormItem::text('title', 'Title')->required()->unique(), | |
FormItem::text('companyName', 'Company Name DE')->lang("de")->required(), | |
FormItem::text('companyName', 'Company Name EN')->lang("en"), | |
FormItem::text('address', 'Address'), | |
FormItem::text('address', 'Address'), | |
FormItem::text('phone', 'Phone'), | |
]); | |
return $form; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Entities; | |
use Illuminate\Database\Eloquent\Model; | |
class Company2 extends Model | |
{ | |
use \Dimsav\Translatable\Translatable; | |
protected $table = 'companies'; | |
protected $fillable = [ | |
'title', | |
'address', | |
'phone' | |
]; | |
protected $hidden = [ | |
'created_at', | |
'updated_at' | |
]; | |
public $translationModel = 'App\Entities\CompanyTranslation'; | |
public $translationForeignKey = "company_id"; | |
public $translatedAttributes = ['companyName']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php namespace App\Entities; | |
use Illuminate\Database\Eloquent\Model; | |
class CompanyTranslation extends Model | |
{ | |
public $timestamps = false; | |
protected $fillable = ['companyName']; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Database\Migrations\Migration; | |
class CompanyTranslation extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('company_translations', function(Blueprint $table) | |
{ | |
$table->increments('id'); | |
$table->integer('company_id')->unsigned(); | |
$table->string('companyName'); | |
$table->string('locale')->index(); | |
$table->unique(['company_id','locale']); | |
$table->foreign('company_id')->references('id')->on('companies')->onDelete('cascade'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('company_translations'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
class CreateCompaniesTable extends Migration { | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('companies', function(Blueprint $table) | |
{ | |
$table->increments('id'); | |
$table->string('title')->unique(); | |
$table->string('address'); | |
$table->string('phone'); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('companies'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Seeder; | |
class CompaniesSeeder extends Seeder | |
{ | |
public function run() | |
{ | |
$faker = Faker\Factory::create(); | |
for ($i = 0; $i < 20; $i++) | |
{ | |
\App\Entities\Company::create([ | |
'title' => $faker->unique()->company, | |
'address' => $faker->streetAddress, | |
'phone' => $faker->phoneNumber, | |
]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment