我试图从 Laravel 5.7 中的表中获取随机数的行,但我找不到任何解决方案。我用过
Model::all()->random(2);
Run Code Online (Sandbox Code Playgroud)
它工作正常。但是我需要像Model::select('column')->where('column','value')->random(number of rows');
这样应用 where 子句,那么我如何使用 eloquent 来实现这一点。请给我任何建议。
我可以在 Laravel 中向 LongText 列添加唯一约束吗?我的意思是,例如我有一个表,其中包含 LongText 数据类型的 body 列,那么我如何使它独一无二。
$table->LongText('body')->unique();
Run Code Online (Sandbox Code Playgroud)
当我这样做时,它会生成以下 SQL 错误。
$table->LongText('body')->unique();
Run Code Online (Sandbox Code Playgroud)
我需要一个解决方案来使 LongText 列独一无二......请给我任何建议。
我需要做以下
Model::select('column')->whereIn('column','!=',array)->first();
Run Code Online (Sandbox Code Playgroud)
所以我怎么能做到这一点。任何建议,谢谢。