src/LaravelPanel/controllers/PanelController.php
public function publish(Request $request, $entity, $record = null, $child = null)
    {
        if (!$record && !$child && ($entityObject = Entity::fromYamlFile($entity))) {
        } elseif (($parentEntity = Entity::fromYamlFile($entity)) && ($entityObject = Entity::fromYamlFile($child))) {
            // Get parent's record
            $parentRecord = $parentEntity->class::findOrFail($record);
        } else {
            abort(404);
        }

        // Get validation from entity rules and validate
        $this->validate($request, $this->validationRules($entityObject->fields));

        // If data is validated and everything seems good, lets create the record
        $record = new $entityObject->class();

        foreach ($entityObject->fields as $field => $options) {
            $type = ucwords($options['type']);
            $className = 'Jaimeeee\\Panel\\Fields\\'.$type.'\\'.$type.'Field';

            if (!isset($className::$ignore) || !$className::$ignore) {
                $record->$field = $request->input($field);
            }
        }

        // Save slug
        if (isset($entityObject->slug['field']) && $entityObject->slug['field'] &&
            isset($entityObject->slug['column']) && $entityObject->slug['column']) {
            $field = $entityObject->slug['field'];
            $column = $entityObject->slug['column'];

            $record->$column = str_slug($record->$field,
                                            isset($entityObject->slug['separator']) ? $entityObject->slug['separator'] : '-');
        }

        // Save parent
        if (isset($parentRecord) && $parentRecord) {
            $row = snake_case(class_basename($parentEntity->class)).'_id';

            $record->$row = $parentRecord->id;
        }

        $record->save();

        foreach ($entityObject->fields as $field => $options) {
            $type = ucwords($options['type']);
            $className = 'Jaimeeee\\Panel\\Fields\\'.$type.'\\'.$type.'Field';

            // Lets see if the call method exists, and if it does, we should trust the field ¯\_(ツ)_/¯
            if (method_exists($className, 'call')) {
                $className::call($request, $record, $field, $options);
            }
        }

        $record->save();

        // Upload single images
        // $this->uploadImages($request, $record, $entityObject);

        if (isset($parentRecord) && $parentRecord) {
            return redirect(config('panel.url').'/'.$parentEntity->url.'/'.$parentRecord->id.'/'.$entityObject->url.'?created=1');
        } else {
            return redirect(config('panel.url').'/'.$entityObject->url.'?created=1');
        }
    }
public function publish(Request $request, $entity, $record = null, $child = null)
    {
        if (!$record && !$child && ($entityObject = Entity::fromYamlFile($entity))) {
        } elseif (($parentEntity = Entity::fromYamlFile($entity)) && ($entityObject = Entity::fromYamlFile($child))) {
            // Get parent's record
            $parentRecord = $parentEntity->class::findOrFail($record);
        } else {
            abort(404);
        }

        // Get validation from entity rules and validate
        $this->validate($request, $this->validationRules($entityObject->fields));

        // If data is validated and everything seems good, lets create the record
        $record = new $entityObject->class();

        foreach ($entityObject->fields as $field => $options) {
            $type = ucwords($options['type']);
            $className = 'Jaimeeee\\Panel\\Fields\\'.$type.'\\'.$type.'Field';

            if (!isset($className::$ignore) || !$className::$ignore) {
                $record->$field = $request->input($field);
            }
        }

        // Save slug
        if (isset($entityObject->slug['field']) && $entityObject->slug['field'] &&
            isset($entityObject->slug['column']) && $entityObject->slug['column']) {
            $field = $entityObject->slug['field'];
            $column = $entityObject->slug['column'];

            $record->$column = str_slug($record->$field,
                                            isset($entityObject->slug['separator']) ? $entityObject->slug['separator'] : '-');
        }

        // Save parent
        if (isset($parentRecord) && $parentRecord) {
            $row = snake_case(class_basename($parentEntity->class)).'_id';

            $record->$row = $parentRecord->id;
        }

        $record->save();

        foreach ($entityObject->fields as $field => $options) {
            $type = ucwords($options['type']);
            $className = 'Jaimeeee\\Panel\\Fields\\'.$type.'\\'.$type.'Field';

            // Lets see if the call method exists, and if it does, we should trust the field ¯\_(ツ)_/¯
            if (method_exists($className, 'call')) {
                $className::call($request, $record, $field, $options);
            }
        }

        $record->save();

        // Upload single images
        // $this->uploadImages($request, $record, $entityObject);

        if (isset($parentRecord) && $parentRecord) {
            return redirect(config('panel.url').'/'.$parentEntity->url.'/'.$parentRecord->id.'/'.$entityObject->url.'?created=1');
        } else {
            return redirect(config('panel.url').'/'.$entityObject->url.'?created=1');
        }
    }
public function publish ( Request $ request , $ entity , $ record = null , $ child = null ) { if ( ! $ record && ! $ child && ( $ entityObject = Entity :: fromYamlFile ( $ entity ) ) ) { } elseif ( ( $ parentEntity = Entity :: fromYamlFile ( $ entity ) ) && ( $ entityObject = Entity :: fromYamlFile ( $ child ) ) ) { // Get parent's record $ parentRecord = $ parentEntity -> class :: findOrFail ( $ record ) ; } else { abort ( 404 ) ; } // Get validation from entity rules and validate $ this -> validate ( $ request , $ this -> validationRules ( $ entityObject -> fields ) ) ; // If data is validated and everything seems good, lets create the record $ record = new $ entityObject -> class ( ) ; foreach ( $ entityObject -> fields as $ field => $ options ) { $ type = ucwords ( $ options [ 'type' ] ) ; $ className = 'Jaimeeee\\Panel\\Fields\\' . $ type . '\\' . $ type . 'Field' ; if ( ! isset ( $ className :: $ ignore ) || ! $ className :: $ ignore ) { $ record -> $ field = $ request -> input ( $ field ) ; } } // Save slug if ( isset ( $ entityObject -> slug [ 'field' ] ) && $ entityObject -> slug [ 'field' ] && isset ( $ entityObject -> slug [ 'column' ] ) && $ entityObject -> slug [ 'column' ] ) { $ field = $ entityObject -> slug [ 'field' ] ; $ column = $ entityObject -> slug [ 'column' ] ; $ record -> $ column = str_slug ( $ record -> $ field , isset ( $ entityObject -> slug [ 'separator' ] ) ? $ entityObject -> slug [ 'separator' ] : '-' ) ; } // Save parent if ( isset ( $ parentRecord ) && $ parentRecord ) { $ row = snake_case ( class_basename ( $ parentEntity -> class ) ) . '_id' ; $ record -> $ row = $ parentRecord -> id ; } $ record -> save ( ) ; foreach ( $ entityObject -> fields as $ field => $ options ) { $ type = ucwords ( $ options [ 'type' ] ) ; $ className = 'Jaimeeee\\Panel\\Fields\\' . $ type . '\\' . $ type . 'Field' ; // Lets see if the call method exists, and if it does, we should trust the field ¯\_(ツ)_/¯ if ( method_exists ( $ className , 'call' ) ) { $ className :: call ( $ request , $ record , $ field , $ options ) ; } } $ record -> save ( ) ; // Upload single images // $this->uploadImages($request, $record, $entityObject); if ( isset ( $ parentRecord ) && $ parentRecord ) { return redirect ( config ( 'panel.url' ) . '/' . $ parentEntity -> url . '/' . $ parentRecord -> id . '/' . $ entityObject -> url . '?created=1' ) ; } else { return redirect ( config ( 'panel.url' ) . '/' . $ entityObject -> url . '?created=1' ) ; } }
Submit the new record.

@return \Illuminate\Http\Response
Submit the new record .