Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/scheme/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将sql转换为Laravel_Laravel_Eloquent - Fatal编程技术网

如何将sql转换为Laravel

如何将sql转换为Laravel,laravel,eloquent,Laravel,Eloquent,我是laravel的新手,在将sql转换为laravel查询时遇到问题 范例 在表格字段1中插入,字段2在不存在的地方选择'value1','value2',从表格中选择1,其中campo='search' 这是我的密码 插入siryus.prespuesto\u anio id、fk\u agencia\u id、anyo、estado、created\u at、updated\u at选择30,42020、'A','2021-04-21 10:35:01','2021-04-21 10:35

我是laravel的新手,在将sql转换为laravel查询时遇到问题

范例

在表格字段1中插入,字段2在不存在的地方选择'value1','value2',从表格中选择1,其中campo='search'

这是我的密码

插入siryus.prespuesto\u anio id、fk\u agencia\u id、anyo、estado、created\u at、updated\u at选择30,42020、'A','2021-04-21 10:35:01','2021-04-21 10:35:01',如果不存在,从prespuesto\u anio中选择1,其中fk\u agencia\u id='4'

我只想在没有具有该值的字段时插入。仅当存在值时才进行插入​​只有满足WHERE时,select才会返回数据

在中,我们有一个简单的SELECT来验证数据是否存在于表中


我想把它转换成示例代码


DB::table'presupuesto_anio'->加入'agencia','presupuesto_anio.fk_agencia_id','agencia.id'->选择'presupuesto_anio.*','agencia.description'->获取

我不明白你的问题,也许这会有帮助:

$check = Model::where('id', 4)->first();
if(!$check){
    Model::create({
        'column1' => 'value1',
        'column2' => 'value2'
    });
}

您尝试过哪些查询生成器语句?我想将其转换为示例代码DB::table'Prespuesto_anio'->加入'agencia'、'Prespuesto_anio.fk_agencia_id'、'agencia.id'->选择'Prespuesto_anio.*'、'agencia.Description'->获取;