Skip to content

Instantly share code, notes, and snippets.

@noxify
Created December 30, 2015 19:20
Show Gist options
  • Save noxify/f8c18e8b56f11c2024e6 to your computer and use it in GitHub Desktop.
Save noxify/f8c18e8b56f11c2024e6 to your computer and use it in GitHub Desktop.
SoaS - Working Example with Ajax Form
<?php
Admin::menu()->url('/')->label('Start page')->icon('fa-dashboard');
Admin::menu()->label('User Management')->icon('fa-book')->items(function ()
{
Admin::menu('Cartalyst\Sentinel\Users\EloquentUser')->icon('fa-user');
Admin::menu('Cartalyst\Sentinel\Roles\EloquentRole')->icon('fa-users');
Admin::menu('SleepingOwl\Admin\Model\Permission')->icon('fa-users');
});
Admin::menu()->label('Data Display Types')->icon('fa-desktop')->items(function ()
{
Admin::menu('App\Entities\News')->label('Table')->icon('fa-table');
});
<?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 ? '&check;' : '-';
}),
]);
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;
});
<?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);
}
}
<?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');
}
}
<?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