模型字段未显示

时间:2018-03-19 23:46:31

标签: laravel laravel-5.6

我有一个带有image,category_id,created-by,updated_by,created_at,updated_at字段的文章表。我将文章翻译存储在一个单独的表中,该表有一个slug,title,subtitle,description,locale fields。

我想使用seo友好的网址,例如articles / category-slug / article-slug

我在ArticeController中尝试了以下代码

Method Illuminate\Database\Query\Builder::mapInto does not exist.

陈旧问题(克里斯回答):但它并没有显示所有字段 enter image description here

我根据Chris的建议更新了上面的代码。但是,我也使用资源集合,它显示上面的代码错误。 错误

<?php

namespace App\Http\Resources\Articles;

use Illuminate\Http\Resources\Json\JsonResource;
use Carbon\Carbon;
use App\Models\ArticleTranslation;

class ArticleResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
          'id' => $this->id,
          'article_url' => '/articles/'.$this->category->slug.'/'.$this->slug,
          'category' => $this->category->name,
          'category_slug' => $this->category->slug,
          'category_url' => '/articles/'.$this->category->slug,
          'image' => url('/').$this->image,
          'author' => $this->creator->name,
          'created' => Carbon::parse($this->created_at)->diffForHumans(),
          'updated' => Carbon::parse($this->updated_at)->diffForHumans(),
          'views' => $this->page_views,
          'title' => $this->title,
          'subtitle' => $this->subtitle,
          'description' => $this->content,
          'links' => [
              'self' => 'link-value',
          ],
        ];
    }
}

ArticleResource

public class TestGrammar extends Python3BaseListener {

public static void main(String[] args) throws IOException {
    PlagiarismPercentage obj = new PlagiarismPercentage();

    String source = obj
            .readFile("C:\\Users\\Paridhi\\quickSort.py");
    ANTLRInputStream inputCharStream = new ANTLRInputStream(new StringReader(source));
    TokenSource lexer = new Python3Lexer(inputCharStream);
    // Python3Lexer lexer = new Python3Lexer(CharStreams.fromString(source));
    Python3Parser parser = new Python3Parser(new CommonTokenStream(lexer));

    ParseTreeWalker.DEFAULT.walk(new Python3BaseListener() {

        AstPrinter astPrinter = new AstPrinter();

        @Override
        public void enterFuncdef(Python3Parser.FuncdefContext ctx) {
            System.out.printf("NAME=%s\n", ctx.NAME().getText());
            // System.out.println(ctx.toString());
            TestGrammar grammar = new TestGrammar();
            StringBuilder str = grammar.explore(ctx, false, 0, new StringBuilder(""));
            System.out.println("----------------------------");
            System.out.println(str);
            System.out.println("----------------------------");
        }
    }, parser.single_input());
}

private StringBuilder explore(RuleContext ctx, boolean verbose, int indentation, StringBuilder str) {
    boolean toBeIgnored = !verbose && ctx.getChildCount() == 1 && ctx.getChild(0) instanceof ParserRuleContext;
    if (!toBeIgnored) {
        String ruleName = Python3Parser.ruleNames[ctx.getRuleIndex()];

        for (int i = 0; i < indentation; i++) {
            System.out.print("  ");

        }

        System.out.println(ruleName + " " + ctx.getText());
        if (indentation != 0) {
            str.append(ruleName + " ");
        }

    }
    for (int i = 0; i < ctx.getChildCount(); i++) {
        ParseTree element = ctx.getChild(i);
        if (element instanceof RuleContext) {
            explore((RuleContext) element, verbose, indentation + (toBeIgnored ? 0 : 1), str);
        }
    }
    return str;
}

}

1 个答案:

答案 0 :(得分:2)

您正在使用仅针对std::for_each(keys_to_delete.begin(), keys_to_delete.end(), [&](const auto& key) { sample_map.erase(key); }); id的选择打开查询,因此您将始终仅限于这些字段。

尝试:

slug