有一个后端(Laravel),它创建页面并将其存储在数据库中。文章标题,文章文字,链接,图像等
问题如何将数据从数据库输出到Laravel模板,即文章标题和文本?
用于创建和存储文章的后端:
public function store(Request $request)
{
$this->validate($request, [
'channel_name' => ['required', 'exists:channels,name', new NotBannedFromChannel()],
'type' => 'required|in:link,img,text,gif',
'title' => 'required|string|between:7,150',
'url' => ['required_if:type,link', 'url', 'active_url', new NotBlockedDomain()],
'photos_id' => 'required_if:type,img|array|max:20',
'gif_id' => 'required_if:type,gif|integer',
]);
// Make sure user is not overdoing it.
if ($this->tooEarlyToCreate(2)) {
return res(429, "Looks like you're over doing it. You can't submit more than 2 posts per minute.");
}
switch ($request->type) {
case 'link':
$data = $this->linkSubmission($request);
break;
case 'img':
$data = $this->imgSubmission($request);
break;
case 'gif':
$data = $this->gifSubmission($request);
break;
case 'text':
$data = $this->textSubmission($request);
break;
}
$channel = $this->getChannelByName($request->channel_name);
try {
$submission = Submission::create([
'title' => $request->title,
'slug' => $slug = $this->slug($request->title),
'url' => $request->type === 'link' ? $request->url : config('app.url').'/c/'.$channel->name.'/'.$slug,
'domain' => $request->type === 'link' ? domain($request->url) : null,
'type' => $request->type,
'channel_name' => $request->channel_name,
'channel_id' => $channel->id,
'nsfw' => $request->input('nsfw', 0),
'rate' => firstRate(),
'user_id' => Auth::id(),
'data' => $data,
]);
event(new SubmissionWasCreated($submission));
} catch (\Exception $exception) {
app('sentry')->captureException($exception);
return res(500, 'Ooops, something went wrong.');
}
if ($request->type === 'img' || $request->type === 'gif') {
$this->updateSubmissionIdForUploadedFile($request, $submission->id);
}
$this->firstLike($submission->id);
return new SubmissionResource(
Submission::find($submission->id)
);
}