[英]I would like to know how I can get some fields in my db Mysql5.7 without using the faker technique in my controller (laravel)
I would like to know how I can get some fields in my db Mysql5.7 without using the faker technique in my controller, my db is not yet populated, if my db was not populated and I did not use this technique? 我想知道如何在不使用控制器中的fakerr技术的情况下在数据库Mysql5.7中获取某些字段,如果尚未填充数据库并且未使用此技术,数据库尚未填充?
class ClientsController extends Controller{
public function index(){
$clients = Client::all()
return view(clients.index);
}
}
try this 尝试这个
public function index(){
$clients = Client::all()
return view('clients.index',['clients' => $clients]);
}
Faker is for generating random fake data to get started with your logic implementation. Faker用于生成随机的伪数据,以开始您的逻辑实现。 There are so many ways you can generate data for your model.
您可以通过多种方法为模型生成数据。 One is through bulk insert.
一种是通过批量插入。 You can add multiple arrays at a time in your seeder.
您可以在播种器中一次添加多个阵列。
Client::insert([
[// data],
[// data],
[// data],
[// data],
[// data]
]);
Populating fields with random data in controller is not a good option. 在控制器中用随机数据填充字段不是一个好的选择。 I would recommend to use seeder without faker library with above code and when you migrate just add --seed parameter and it will work for you.
我建议使用不带伪造者库的上述种子代码,并且在迁移时只需添加--seed参数,它将对您有用。 You can use tinker too for this purpose.
您也可以为此使用修补匠。 just paste the above code(with data arrays) in tinker and it will work for you.
只需将上面的代码(带有数据数组)粘贴到修补程序中,它将对您有用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.