出于实践目的,我正在使用mysqlite数据库和laravel。我使用php artisan make:model Channel --fmc命令创建一个模型,然后在迁移文件中包含名称字段并运行php artisan migration。通过使用php artisan tinker,我填充了database / database.sqlite文件。通过运行 修补程序上的App \ Channel :: all(),它显示所有记录。但是问题是,当我尝试获取ChannelController.php中的所有记录时,它显示错误。我的代码中的问题在哪里?
ChannelController.php
namespace App\Http\Controllers;
use App\Channel;
use Illuminate\Http\Request;
class ChannelController extends Controller
{
public function index()
{
$channels = Channel::all();
dd($channels->name);
return view('channel.index',compact($channels));
}
}
web.php
Route::get('channels','ChannelController@index');
ChannelFactroy.php
use App\Channel;
use Faker\Generator as Faker;
$factory->define(Channel::class, function (Faker $faker) {
return [
'name' => $faker->word,
];
});
错误
Illuminate\Database\QueryException
SQLSTATE[HY000] [2002] No connection could be made because the target machine actively refused it.
(SQL: select * from `channels`)
和
catch (Exception $e) {
throw new QueryException(
$query, $this->prepareBindings($bindings), $e
);
}