Created
December 30, 2015 19:20
-
-
Save noxify/f8c18e8b56f11c2024e6 to your computer and use it in GitHub Desktop.
SoaS - 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\News')->title('News')->display(function () | |
{ | |
$display = AdminDisplay::table(); | |
$display->scope('last'); | |
$display->columns([ | |
Column::string('title')->label('Title'), | |
Column::datetime('date')->label('Date')->format('d.m.Y'), | |
Column::custom()->label('Published')->callback(function ($instance) | |
{ | |
return $instance->published ? '✓' : '-'; | |
}), | |
]); | |
return $display; | |
})->createAndEdit(function () | |
{ | |
$form = AdminForm::form(); | |
$form->ajax_validation(true); | |
$form->items([ | |
FormItem::text('title', 'Title')->required(), | |
FormItem::date('date', 'Date')->required()->format('d.m.Y'), | |
FormItem::checkbox('published', 'Published'), | |
FormItem::ckeditor('text', 'Text'), | |
]); | |
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 News extends Model | |
{ | |
protected $table = 'news'; | |
protected $fillable = [ | |
'title', | |
'date', | |
'published', | |
'text', | |
]; | |
public function scopeLast($query) | |
{ | |
$query->orderBy('date', 'desc')->limit(4); | |
} | |
public function scopeOld($query) | |
{ | |
$query->orderBy('date', 'asc')->limit(4); | |
} | |
} |
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 CreateNewsTable extends Migration { | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::create('news', function(Blueprint $table) | |
{ | |
$table->increments('id'); | |
$table->string('title'); | |
$table->date('date'); | |
$table->boolean('published'); | |
$table->text('text'); | |
$table->timestamps(); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::drop('news'); | |
} | |
} |
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 NewsSeeder extends Seeder | |
{ | |
public function run() | |
{ | |
$faker = Faker\Factory::create(); | |
for ($i = 0; $i < 20; $i++) | |
{ | |
\App\Entities\News::create([ | |
'title' => $faker->unique()->sentence(4), | |
'date' => $faker->dateTimeThisCentury, | |
'published' => $faker->boolean(), | |
'text' => $faker->paragraph(5), | |
]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment