我有一个带有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.
我根据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;
}
}
答案 0 :(得分:2)
您正在使用仅针对std::for_each(keys_to_delete.begin(), keys_to_delete.end(), [&](const auto& key) { sample_map.erase(key); });
和id
的选择打开查询,因此您将始终仅限于这些字段。
尝试:
slug