Пример #1
0
 /**
  * Search the metadata table data associated with the given model.
  * Assigns a new attribute inside of the model - 'meta'.
  * @return MetaCollection
  */
 public static function retrieve(Model $model)
 {
     if ($model->meta) {
         return $model->meta;
     }
     // Object can either be the UID or the model class.
     // Model class tends to be global for all of that model.
     // However, UID keys will override class keys.
     return static::where('object', $model->getAttribute('uid'))->orWhere('object', get_class($model))->get();
 }
Пример #2
0
 public function child($class)
 {
     if (class_exists($class)) {
         $this->class = $class;
         $method = $class::plural();
         $this->related = method_exists($this->model, $method) ? $this->model->{$method}()->get() : $this->model->related($class);
         $this->actions->add(Button::create()->parent($class)->link('create')->classes('button success'));
     }
     return $this;
 }
Пример #3
0
 /**
  * Return an array of rules for the laravel validator.
  * @return array
  */
 public function rules()
 {
     $rules = array();
     if ($this->isEmpty()) {
         return $rules;
     }
     $class = $this->class;
     $table = $this->parent ? $this->parent->getTable() : with(new $class())->getTable();
     $types = [Input::EMAIL => 'email', Input::NUMBER => 'numeric', Input::DATE => 'date', Input::TOGGLE => 'boolean', Input::TEXT => 'string', Input::SLUG => 'alpha_dash', Input::MODEL => 'integer'];
     foreach ($this->items as $input) {
         $rule = array();
         if ($input->required) {
             $rule[] = "required";
         }
         if ($input->unique) {
             // unique:posts,slug,{id to exclude}
             $rule[] = "unique:" . $table . "," . $input->name . ($this->parent ? "," . $this->parent->id : "");
         }
         if (array_key_exists($input->type, $types)) {
             $rule[] = $types[$input->type];
         }
         if (!empty($rule)) {
             $rules[$input->name] = join("|", $rule);
         }
     }
     return $rules;
 }
Пример #4
0
 /**
  * Relate all items in this collection to the given model.
  * @param $model string|Model
  * @return bool|null
  */
 public function attach($model)
 {
     if (is_string($model)) {
         $model = Model::str($model);
     }
     if (!$model) {
         return null;
     }
     foreach ($this->items as $media) {
         $model->relate($media);
     }
     return true;
 }
Пример #5
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $this->seed_classes = config('database.seeds');
     Model::unguard();
     // Instantiate the seeds.
     foreach ($this->seed_classes as $class) {
         if (!class_exists($class)) {
             continue;
         }
         $this->call($class);
     }
     Model::reguard();
 }
Пример #6
0
 /**
  * Update the specified resource in storage.
  * @usage /models/edit/1
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function update(Model $model, Request $request)
 {
     $class = $this->setClass($model->getClass());
     $input = $request->all();
     $validator = $model->validate($input);
     if ($validator->fails()) {
         return CMSResponse::failed($validator->errors()->all());
     }
     if ($model->update($input)) {
         return CMSResponse::updated($model);
     }
     // Something else went wrong...
     return CMSResponse::failed($model);
 }
Пример #7
0
 /**
  * Return the inputs for the given model.
  * Looks for model class and model uid as the 'object' field.
  * @param $model Model
  * @return mixed
  */
 public static function retrieve(Model $model)
 {
     if (!empty($model->inputs)) {
         return $model->inputs;
     }
     $inputs = static::where('object', $model->getAttribute('uid'))->orWhere('object', get_class($model))->orderBy('priority', 'asc')->get();
     $inputs->setParent($model);
     return $inputs;
 }
Пример #8
0
 /**
  * Delete the media from the database and from the server.
  * @return bool
  * @throws \Exception
  */
 public function delete()
 {
     // Delete any files, including sizes.
     try {
         if ($this->sizes) {
             foreach ($this->sizes as $key => $url) {
                 unlink($this->path($key));
             }
         }
         unlink($this->path());
     } catch (\ErrorException $e) {
         // File probably doesn't exist, so delete anyway.
     }
     Relationship::clear($this);
     return parent::delete();
 }
Пример #9
0
 /**
  * Removes any relationships for a given model.
  * @param Model $model
  * @return array
  */
 public static function clear(Model $model)
 {
     $parents = DB::table('relationships')->where('parent_id', $model->id)->where('parent_object', $model->getClass())->delete();
     $children = DB::table('relationships')->where('child_id', $model->id)->where('child_object', $model->getClass())->delete();
     return ['parents' => $parents, 'children' => $children];
 }
Пример #10
0
 /**
  * Displays the media selection tool dialog.
  * GET /media/list?parent=Birdmin\Page\1
  * @param Request $request
  * @return \Illuminate\Http\Response
  */
 public function select(Request $request)
 {
     $media = Media::request($request, $this->user, 30);
     $parent = Model::str($request->input('parent'));
     return view('cms::media.select', compact('media', 'parent'));
 }
Пример #11
0
 /**
  * Set the template title, description and image given the model.
  * @param Model $model
  */
 public function model(Model $model)
 {
     $this->title = $model->getTitle() . " - " . config('app.client_name');
     if ($model instanceof Page) {
         $this->description = Str::limit(strip_tags($model->content), 160);
     } else {
         $this->description = $model->excerpt ?: Str::limit(strip_tags($model->description), 160);
     }
     if ($image = $model->getImage()) {
         $this->image = $image->url(null, false);
     } else {
         $this->image = url(config('app.client_logo'));
     }
 }
Пример #12
0
 /**
  * Attach the parent model.
  * @param Model $model
  * @return $this
  */
 public function parent(Model $model)
 {
     $this->model = $model;
     $this->media = $model->media();
     return $this;
 }