/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle(Request $request, Closure $next) { $modelIndex = Application::context(Application::CXT_API) ? 3 : 2; $idIndex = Application::context(Application::CXT_API) ? $modelIndex + 1 : $modelIndex + 2; // Check for the model slug. Throw 404 if not found. $modelSegment = $request->segment($modelIndex); $idSegment = $request->segment($idIndex); $blueprint = ModelBlueprint::slug($modelSegment); if (!$blueprint) { $message = "Class for '{$modelSegment}' does not exist"; return Application::context(Application::CXT_API) ? RESTResponse::failed($message, 404) : response($message, 404); } $class = $blueprint->getClass(); // Check if the model ID was given. if ($idSegment) { $model = $class::find($idSegment); if (!$model) { $message = "Model '{$modelSegment}/{$idSegment}' does not exist"; return Application::context(Application::CXT_API) ? RESTResponse::failed($message, 404) : response($message, 404); } $request->Model = $model; return $next($request); } // Otherwise, return the static model class. $request->Model = new $class(); return $next($request); }
/** * Install inputs for each model. * Encapsulate values if need be by the ` character. * * @return void */ public function run() { $config = Model::$config; foreach ($config as $class => $data) { // Use the blueprint first. if ($blueprint = ModelBlueprint::get($class)) { $arr = $blueprint->getInputsArray(); foreach ($arr as $input) { $this->createIfNotExisting($input); } continue; } // Otherwise, use deprecated stuff. foreach ($data['fields'] as $input) { $this->createIfNotExisting($input); } } echo sizeof($this->created) . " Input objects created.\n"; }
/** * Create a array, for Input::create(). * @return array */ public function toInputArray() { return ['object' => $this->blueprint->getClass(), 'name' => $this->name, 'label' => $this->label, 'priority' => $this->priority, 'description' => $this->description, 'type' => $this->input, 'options' => $this->options ? json_encode($this->options) : "", 'required' => $this->required ? 1 : 0, 'unique' => $this->unique ? 1 : 0, 'in_table' => $this->in_table ? 1 : 0, 'value' => $this->value ?: "", 'active' => 1]; }
use Birdmin\Support\ModelBlueprint; use Birdmin\Support\FieldBlueprint as Field; use Birdmin\Input; use Birdmin\User; use Birdmin\Role; use Birdmin\Media; /** * ------------------------------------------ * USER MODEL * ------------------------------------------ */ $users = ModelBlueprint::create(User::class, 'users')->_email('Email Address', Field::TITLE, Input::EMAIL)->_first_name('First Name', Field::STRING, Input::TEXT)->_last_name('Last Name', Field::STRING, Input::TEXT)->_phone('Phone', Field::STRING, Input::TEXT)->_password('Password', Field::STRING, Input::PASSWORD)->_website('Website', Field::STRING, Input::URL)->_affiliation('Affiliation', Field::STRING, Input::TEXT)->_position('Position', Field::STRING, Input::TEXT)->_bio('Personal Info', Field::TEXT, Input::HTML)->in_table(['email', 'first_name', 'last_name', 'phone'])->unique(['email'])->required(['email', 'first_name', 'last_name'])->hidden(['password'])->permissions(['view', 'manage', 'create', 'edit', 'delete'])->no_image('/cms/public/images/no-user.svg')->icon('users2')->public(false); /** * ------------------------------------------ * ROLE MODEL * ------------------------------------------ */ $roles = ModelBlueprint::create(Role::class, "roles")->_name('Name', Field::TITLE, Input::TEXT)->_description('Description', Field::TEXT, Input::TEXTAREA)->in_table(['name', 'description'])->unique(['name'])->required(['name'])->icon('user-lock')->public(false); /** * ------------------------------------------ * MEDIA MODEL * ------------------------------------------ */ $media = ModelBlueprint::create(Media::class, "media")->_title('Title', Field::TITLE, Input::TEXT)->_alt_text('Alt Text', Field::STRING, Input::TEXT)->_file_name('File Name', Field::STRING, Input::NONE)->_file_type('File Type', Field::STRING, Input::NONE)->_file_size('File Size', Field::INTEGER, Input::NONE)->_category('Category', Field::STRING, Input::TEXT)->_caption('Caption', Field::TEXT, Input::TEXTAREA)->_metadata('Metadata', Field::TEXT, Input::HASH)->_etag('ETag', Field::TEXT)->in_table(['file_name', 'file_type', 'file_size', 'title'])->required(['file_name', 'file_type', 'title'])->icon('picture')->public(false); /** * ------------------------------------------ * INPUT MODEL * ------------------------------------------ */ $inputs = ModelBlueprint::create(Input::class, "inputs")->_label("Label", Field::TITLE, Input::TEXT)->_object("Object", Field::STRING, Input::TEXT)->_name("Name", Field::STRING, Input::TEXT)->_type("Type", Field::STRING, Input::TEXT)->_options("Options", Field::TEXT, Input::CODE)->_description("Description", Field::TEXT, Input::TEXTAREA)->_in_table("In Table", Field::INTEGER, Input::TOGGLE)->_required("Required", Field::INTEGER, Input::TOGGLE)->_unique("Unique", Field::INTEGER, Input::TOGGLE)->_priority("Priority", Field::INTEGER, Input::NUMBER)->in_table(['label', 'object', 'name', 'type', 'priority'])->required(['label', 'object', 'name', 'type'])->icon('select2')->public(false)->labels(['navigation' => "Input Register"]);
/** * Return a blueprint from the static array. * @param $class string * @return null|ModelBlueprint */ public static function get($class) { return ModelBlueprint::exists($class) ? ModelBlueprint::$blueprints[$class] : null; }
<?php use Birdmin\Support\ModelBlueprint; use Birdmin\Support\FieldBlueprint as Field; use Birdmin\Input; use Birdmin\Location; /** * ------------------------------------------ * LOCATION MODEL * ------------------------------------------ */ $locations = ModelBlueprint::create(Location::class, "locations")->_name("Name", Field::TITLE, Input::TEXT)->_address("Address", Field::STRING, Input::TEXT)->_address_2("Address Line 2", Field::STRING, Input::TEXT)->_city("City", Field::STRING, Input::TEXT)->_state("State", Field::STRING, Input::SELECT, ['values' => 'states'])->_zip("Postal Code", Field::STRING, Input::TEXT)->_county("County", Field::STRING, Input::TEXT)->_country("Country", Field::STRING, Input::SELECT, ['values' => 'countries'])->_lat("Latitude", [Field::FLOAT, 6], Input::NUMBER)->_lng("Longitude", [Field::FLOAT, 6], Input::NUMBER)->_description("Description", Field::TEXT, Input::HTML)->_directions("Directions", Field::TEXT, Input::HTML)->fillable('*')->in_table(['name', 'address', 'city', 'state'])->required(['name'])->icon('map-marker');
/** * Return the blueprint object from the collection. * @return ModelBlueprint|null */ public static function blueprint() { return ModelBlueprint::get(static::class); }
<?php use Birdmin\Support\ModelBlueprint; use Birdmin\Support\FieldBlueprint as Field; use Birdmin\Input; use Birdmin\Page; use Birdmin\Category; use Birdmin\User; use Birdmin\Post; /** * ------------------------------------------ * PAGE MODEL * ------------------------------------------ */ $pages = ModelBlueprint::create(Page::class, 'pages')->_title("Title", Field::TITLE, Input::TEXT)->_slug('Slug', Field::SLUG, Input::SLUG, ['references' => 'title'])->_content("Content", Field::TEXT, Input::HTML)->_status("Status", Field::STATUS, Input::RADIO, ['values' => Input::$statusFields])->_type("Type", Field::STRING, Input::RADIO)->_parent_id("Parent Page", [Field::REFERENCE, ['pages', 'id']], Input::MODEL)->_user_id("Author", [Field::REFERENCE, ['users', 'id']], Input::MODEL)->fillable('*')->in_table(['title', 'status', 'slug'])->searchable(['title', 'status', 'type'])->unique(['slug'])->required(['slug', 'status'])->icon('file-empty')->setOptions(['type' => ['values' => ['normal' => 'Normal', 'landing' => 'Landing Page']], 'parent_id' => ['model' => Page::class, 'nullable' => true], 'user_id' => ['model' => User::class, 'nullable' => false]]); /** * ------------------------------------------ * CATEGORY MODEL * ------------------------------------------ */ $categories = ModelBlueprint::create(Category::class, 'categories')->_name('Name', Field::TITLE, Input::TEXT)->_slug('Slug', Field::SLUG, Input::SLUG, ['references' => 'name'])->_description('Description', Field::TEXT, Input::HTML)->_status('Status', Field::STATUS, Input::RADIO, ['values' => Input::$statusFields])->_excerpt('Excerpt', Field::STRING, Input::TEXTAREA)->_object('Object Type', Field::STRING, Input::TEXT)->_parent_id('Parent Category', [Field::REFERENCE, ['categories', 'id']], Input::MODEL)->fillable('*')->in_table(['name', 'status', 'object', 'parent_id'])->searchable(['name', 'status', 'object'])->unique(['slug'])->required(['name', 'slug'])->icon('tag')->url('category/{slug}')->setOptions(['parent_id' => ['model' => Category::class, 'nullable' => true]]); /** * ------------------------------------------ * POST MODEL * ------------------------------------------ */ $posts = ModelBlueprint::create(Post::class, "posts")->_title('Title', Field::TITLE, Input::TEXT)->_slug('Slug', Field::SLUG, Input::SLUG, ['references' => 'title'])->_user_id('Author', [Field::REFERENCE, ['users', 'id']], Input::MODEL)->_excerpt('Excerpt', Field::TEXT, Input::TEXTAREA)->_content('Content', Field::TEXT, Input::HTML)->_published_at('Publish Date', Field::DATE, Input::DATE)->_status('Status', Field::STATUS, Input::RADIO, ['values' => Input::$statusFields])->_type('Post Type', Field::STRING, Input::SELECT)->_location_id('Location', [Field::REFERENCE, ['locations', 'id']])->in_table(['title', 'user_id', 'published_at', 'status'])->unique(['slug'])->required(['title', 'slug', 'user_id'])->dates(['published_at'])->icon('files')->setOptions(['type' => ['values' => ['post' => 'Post', 'revision' => 'Revision']], 'user_id' => ['model' => 'Birdmin\\User', 'nullable' => false]]);
<?php use Birdmin\Support\ModelBlueprint; use Birdmin\Support\FieldBlueprint as Field; use Birdmin\Input; use Birdmin\Lead; /** * ------------------------------------------ * LEAD MODEL * ------------------------------------------ */ $leads = ModelBlueprint::create(Lead::class, 'leads')->_email('Email Address', Field::TITLE, Input::EMAIL)->_first_name('First Name', Field::STRING, Input::TEXT)->_last_name('Last Name', Field::STRING, Input::TEXT)->_affiliation('Affiliation', Field::STRING, Input::TEXT)->_phone('Phone', Field::STRING, Input::TEXT)->_source('Source', Field::STRING, Input::TEXT)->_interest('Interest', Field::STRING, Input::TEXT)->_type('Type', Field::STRING, Input::TEXT)->_comments('Comments', Field::TEXT, Input::TEXTAREA)->_notes('Notes', Field::TEXT, Input::TEXTAREA)->_session_id('Session ID', Field::STRING, Input::NONE)->_valid('Valid', Field::INTEGER, Input::NONE)->useTimestamps()->fillable('*')->in_table(['email', 'first_name', 'last_name', 'affiliation', 'source'])->searchable(['email', 'affiliation', 'source'])->required(['email'])->icon('users2')->no_image('/cms/public/images/no-user.svg')->url('leads/{uid}')->public(false);
<?php use Birdmin\Support\ModelBlueprint; use Birdmin\Support\FieldBlueprint as Field; use Birdmin\Input; use Birdmin\Product; use Birdmin\ProductVariation; use Birdmin\ProductBundle; /** * ------------------------------------------ * PRODUCT MODEL * ------------------------------------------ */ $products = ModelBlueprint::create(Product::class, 'products')->_name("Name", Field::TITLE, Input::TEXT)->_slug('Slug', Field::SLUG, Input::SLUG, ['reference' => 'name'])->_status("Status", Field::STATUS, Input::RADIO, ['values' => Input::$statusFields])->_brand("Brand", Field::TEXT, Input::TEXT)->_sku("SKU", Field::STRING, Input::TEXT)->_excerpt("Excerpt", Field::STRING, Input::TEXTAREA)->_description("Description", Field::TEXT, Input::HTML)->_category_id("Category", [Field::REFERENCE, ['id', 'categories']], Input::MODEL)->_bundle_id("Product Bundle", [Field::REFERENCE, ['id', 'product_bundles']], Input::MODEL)->_type("Type", Field::STRING, Input::TEXT)->_attributes("Attributes", Field::TEXT, Input::HTML)->useTimestamps()->useSoftDeletes()->fillable('*')->in_table(['name', 'brand', 'type', 'sku', 'status'])->searchable(['name', 'sku', 'brand', 'status'])->unique(['slug', 'sku'])->required(['name', 'slug', 'status'])->public(true)->icon('bag')->no_image('/public/images/no-image.svg')->url('products/{slug}')->module('Birdmin\\Components\\RelatedMedia')->module('Birdmin\\Components\\RelatedModels', ['Birdmin\\ProductVariation'])->setOptions(['category_id' => ['model' => \Birdmin\Category::class, 'nullable' => true], 'bundle_id' => ['model' => \Birdmin\ProductBundle::class, 'nullable' => true]]); /** * ------------------------------------------ * VARIATION MODEL * ------------------------------------------ */ $variations = ModelBlueprint::create(ProductVariation::class, 'product_variations')->_name("Name", Field::TITLE, Input::TEXT)->_product_id("Parent Product", [Field::REFERENCE, ['id', 'products']], Input::MODEL)->_status("Status", Field::STATUS, Input::RADIO, ['values' => Input::$statusFields])->_sku("SKU", Field::STRING, Input::TEXT)->_description("Description", Field::TEXT, Input::HTML)->_attributes("Attributes", Field::TEXT, Input::HTML)->_color("Color", Field::STRING, Input::COLOR)->_color_name("Color Name", Field::STRING, Input::TEXT)->useTimestamps()->useSoftDeletes()->fillable('*')->in_table(['name', 'color', 'product_id', 'sku', 'status'])->searchable(['name', 'status', 'sku'])->unique(['sku'])->required(['name', 'status', 'product_id', 'sku'])->icon('bag')->no_image('/public/images/no-image.svg')->url('variation/{slug}')->module('Birdmin\\Components\\RelatedMedia')->setOptions(['product_id' => ['model' => \Birdmin\Product::class, 'nullable' => false]]); /** * ------------------------------------------ * PRODUCT BUNDLE MODEL * ------------------------------------------ */ $bundles = ModelBlueprint::create(ProductBundle::class, 'product_bundles')->_name("Name", Field::TITLE, Input::TEXT)->_slug('Slug', Field::SLUG, Input::SLUG)->_brand('Brand', Field::STRING, Input::TEXT)->_website("Website", Field::STRING, Input::URL)->_excerpt("Excerpt", Field::TEXT, Input::HTML)->_attributes("Attributes", Field::TEXT, Input::HTML)->_description("Description", Field::TEXT, Input::HTML)->_status("Status", Field::STATUS, Input::RADIO, ['values' => Input::$statusFields])->_redirect("Redirect URL", Field::TEXT, Input::URL)->useTimestamps()->useSoftDeletes()->fillable('*')->in_table(['name', 'brand', 'excerpt', 'website'])->searchable(['name', 'brand'])->unique(['slug'])->required(['name', 'brand', 'slug'])->icon('bag')->no_image('/public/images/no-image.svg')->url('bundle/{slug}')->module('Birdmin\\Components\\RelatedMedia');