Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
438 views
in Technique[技术] by (71.8m points)

php - 与Laravel语法错误混淆:意外的“。” (对我来说似乎很好)(Confused with a Laravel syntax error: unexpected '.' (seems fine to me))

I'm new to Laravel.

(我是Laravel的新手。)

I keep getting this syntax error:

(我不断收到此语法错误:)

SymfonyComponentDebugExceptionFatalThrowableError
syntax error, unexpected '.' 

The line in question is this:

(有问题的行是这样的:)

  $post = .DB::table('posts')->where('slug', $slug)->first();

Here's the entire code that is not working:

(这是整个无效的代码:)

<?php

namespace AppHttpControllers;

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]
      ]);
  }

}

What is it that I am missing here!?

(我在这里想念什么!?)

Thanks

(谢谢)

  ask by henry translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You shouldn't use .\ .

(您不应该使用.\ 。)

Please change your code $post = .\DB::table('posts')->where('slug', $slug)->first();

(请更改您的代码$post = .\DB::table('posts')->where('slug', $slug)->first();)

with $post = DB::table('posts')->where('slug', $slug)->first();

(与$post = DB::table('posts')->where('slug', $slug)->first();)

and don't forget to import DB use DB

(并且不要忘记use DB导入use DB)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...