【发布时间】:2019-12-01 06:15:10
【问题描述】:
我是 Laravel 的新手。
我不断收到此语法错误:
Symfony\Component\Debug\Exception\FatalThrowableError
syntax error, unexpected '.'
有问题的行是这样的:
$post = .\DB::table('posts')->where('slug', $slug)->first();
这是不工作的整个代码:
<?php
namespace App\Http\Controllers;
class PostsController extends Controller
{
public function show($slug)
{
$post = .\DB::table('posts')->where('slug', $slug)->first();
dd($post);
// This was to simulate a database
// $posts = [
// 'my-first-post' => 'Hello This is my first blog post',
// 'my-second-post' => 'Hello This is my second blog post',
// ];
// if it doesn't exist then throw this error:
if (! array_key_exists($post, $posts)){
abort(404, 'Sorry, that post was not found.');
}
// return this view:
return view('post', [
'post' => $posts[$post]
]);
}
}
我在这里错过了什么!?
谢谢
【问题讨论】:
-
您认为使用
.对$post分配有何作用?为什么你认为这很好?