与 Laravel 修补匠一起工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31947082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:09:38  来源:igfitidea点击:

Work with laravel tinker

phplaravelcygwin

提问by amirhtk

I'm new to laravel .

我是 laravel 的新手。

I want to work with php artisan tinker in cygwin but I am getting some errors in making an object. I watched some videos and the guy did this:

我想在 cygwin 中使用 php artisan tinker,但是我在制作对象时遇到了一些错误。我看了一些视频,这个人是这样做的:

$article = new app\articles;

but when I do this it says:

但是当我这样做时,它说:

PHP Fatal error:  Class 'app\articles' not found in eval()'d code on line 1

I tried this too:

我也试过这个:

$article = new c://xampp/htdocs/laravel/app/articles;

but it says this:

但它是这样说的:

PHP Parse error: Syntax error, unexpected ':' on line 1

回答by Dimitri Acosta

Tinker is case sensitive so if you are trying to create the object the way you are doing it it will fail so instead try placing the whole namespace in the exact way it is on your project

Tinker 区分大小写,因此如果您尝试按照您的方式创建对象,它将失败,因此请尝试按照项目中的确切方式放置整个命名空间

$article = new App\Article;

$article = new App\Article;

回答by user3426711

Use terminal to go to your project, and type :

使用终端转到您的项目,然后键入:

php artisan tinker

Then type the following command for example to create a new Article:

然后键入以下命令,例如创建一个新的Article

$article = new Article;

After that you can manipulate the article like any Articleobject :

之后,您可以像操作任何Article对象一样操作文章:

$article->title = "foo";

Maybe you should take a look at Laravel Fundamentalsat laracasts.com, it's a greate serie for Laravel beginners.

也许你应该看看Laravel基本面laracasts.com,它是Laravel初学者马丽娟系列。

Regards.

问候。