/** * set Content Method */ public function setContent($content) { if ($this->id) { $validator = Validator::make($content, Channel::findOrFail($this->channel_id)->fields); if ($validator->fails()) { throw new \InvalidArgumentException(head(array_flatten($validator->messages()))); } $this->content = $content; return; } throw new \InvalidArgumentException("Primary Key Not Set."); }
/** * Get the services provided by the provider. * * @return array */ public function boot() { Channel::saved(function ($channel) { $channels = var_export(Channel::all()->toArray(), true); file_put_contents(config_path() . "/content-entry.php", "<?php return {$channels};"); }); Channel::deleted(function ($channel) { $channels = var_export(Channel::all()->toArray(), true); file_put_contents(config_path() . "/content-entry.php", "<?php return {$channels};"); }); Entry::saved(function ($entry) { $channel = Channel::findOrFail($entry->channel_id); event("{$channel->name}.saved"); }); Entry::deleted(function ($entry) { $channel = Channel::findOrFail($entry->channel_id); event("{$channel->name}.deleted"); }); $this->publishes([__DIR__ . '/../../../config/content-entry.php' => config_path('content-entry.php')]); $this->publishes([__DIR__ . "/../../..//migrations" => database_path('migrations')], 'migrations'); }
/** * In certain cases a channel may exist in config but not in * Schema. This is the answer to that. */ private function updateSchema() { //redo everything... Channel::truncate(); $this->channelConfig->map(function ($channel) { extract($channel); $fields = json_encode($fields); $relatable = json_encode($relatable); Channel::insert(compact('id', 'name', 'fields', 'relatable', 'created_at', 'updated_at')); }); }