我正在学习Laravel教程,遇到了一个“调用未定义函数”错误。到目前为止,我有20个测试和28个断言,只有这个测试失败。我找不到我的打字错误。请告诉我我还需要添加哪些源代码。我是拉雷维尔的新手。
λ vendor\bin\phpunit --filter a_user_can_filter_threads_according_to_a_channel
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
E 1 / 1 (100%)
Time: 409 ms, Memory: 14.00MB
There was 1 error:
1) Tests\Feature\ReadThreadsTest::a_user_can_filter_threads_according_to_a_channel
Symfony\Component\Debug\Exception\FatalThrowableError: Call to undefined function App\Http\Controllers\get()
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
一定是打错了,但我找不到。
ReadThreadsTest.php
/** @test */
public function a_user_can_filter_threads_according_to_a_channel()
{
$channel = create('App\Channel');
$threadInChannel = create('App\Thread', ['channel_id' => $channel->id]);
$threadNotInChannel = create('App\Thread');
$this->get('/threads/' . $channel->slug)
->assertSee($threadInChannel->title)
->assertDontSee($threadNotInChannel->title);
}
web.php
Route::get('threads/{channel}', 'ThreadsController@index');
Channel.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Channel extends Model
{
public function getRouteKeyName()
{
return 'slug';
}
public function threads()
{
return $this->hasMany(Thread::class);
}
}
ThreadController.php
public function index(Channel $channel)
{
if ($channel->exists)
{
$threads = $channel->threads()->latest()-get();
} else {
$threads = Thread::latest()->get();
}
return view('threads.index', compact('threads'));
}
Thread.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Thread extends Model
{
protected $guarded = [];
public function path()
{
return "/threads/{$this->channel->slug}/{$this->id}";
}
public function replies()
{
return $this->hasMany(Reply::class);
}
public function creator()
{
return $this->belongsTo(User::class, 'user_id');
}
public function channel()
{
return $this->belongsTo(Channel::class);
}
public function addReply($reply)
{
$this->replies()->create($reply);
}
}
经过几个小时的搜索,我终于找到了我的错字...
这个:
$threads = $channel->threads()->latest()-get();
必须是:
$threads = $channel->threads()->latest()->get();
现在一切都好了。
我是laravel的新手,我正在开发一个文件上传系统。文件上载并存储到数据库中很好,但当我尝试调用delete方法时,它会给出以下错误:
我正在尝试将一个Laravel5.7项目转换为8,仍在调试,但无法解决这个特殊问题。 当我运行该项目时,出现“调用未定义函数App\Http\Controllers\get\u option()”错误。 我试过: 将helpers.php位置提供程序更改为控制器 这是App\Http\Controllers\MainpageController中的错误源: 这是app/Providers/help
我的函数出现此错误。我正在尝试在按用户id提交报告之间添加5分钟计时器。但由于某些原因,我出现此错误。 这是我的控制器
在laravel 5.4i中定义在helper方法中 但在拉拉维尔7号不行!
我有一个类调用VSE,其中有50多个函数。 我想列出所有这些函数。 我试过了 我一直得到 我做错了什么?