简体   繁体   English

我想知道如何在我的数据库Mysql5.7中获取一些字段,而无需在控制器中使用fakerr技术(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 (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.

相关问题 我怎样才能保存我的价值<input type='checkbox'>使用 Laravel 5.7 代码到 MySQL 数据库? - How can I save the value of my <input type='checkbox'> to MySQL Database with laravel 5.7 code? Laravel:如何在我的 Laravel faker 中生成两个独特的种子 - Laravel: How can i generate two unique seeds in my laravel faker 如何在 Laravel 的控制器中获取 lang - How can I get the lang inside my controller in laravel 如何在 Laravel 中使用 Faker 格式化程序创建随机名称? - How can I create a random name using Faker formatters in Laravel? 如何避免在返回 Laravel 5.7 数据库层中的主键的结果上使用 `array_map`? - How I can avoid using `array_map` on my results returning primary keys in Laravel's 5.7 database layer? 我想知道一个对象是否在我的Doctrine Collection中 - I would like to know if an object is in my Doctrine Collection 我怎么知道我的页面中的facebook按钮是否被选中 - How can I know if facebook like button in my page is checked Laravel-我知道我的ViewModel,那么我可以将该ViewModel传递到控制器参数中吗? - Laravel - I know my ViewModel, so can i pass that ViewModel through into the controller parameters? 我如何知道使用PHP生成的图像是从我的网站还是其他网站请求的? - How can I know whether the image generated using PHP is requested from my website or some other website? 在laravel 5.7中使用ajax技术 - using ajax technique in laravel 5.7
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM