我使用以下插入数组在Laravel中插入多个条目 Eloquent ORM
$i = 0;
foreach($exerciseValArray as $kkey=>$exerciseValue){
if($exerciseValue['exercise'] =='' || $exerciseValue['section_type'] == ''){
return Response::JSON(array('errors'=>array('Error in workout exercise section')));
}
$exerciseData = explode(',',$exerciseValue['exercise']);
foreach($exerciseData as $exerciseid){
$insertArray[$i]['fk_workouts_id'] = $id;
$insertArray[$i]['fk_users_id'] = $userId;
$insertArray[$i]['fk_exercises_id']= $exerciseid;
$insertArray[$i]['section'] = $exerciseValue['section_type'];
$insertArray[$i]['status'] = 1;
$insertArray[$i]['item_index'] = $index+$kkey+1;
$insertArray[$i]['updated_at'] = $workoutDetails['updated_at'];
$i++;
}
}
WorkoutExercise::insert($insertArray);
Run Code Online (Sandbox Code Playgroud)
上面的代码工作正常,并将数据数组插入到数据库中.
我已成功学习了Model::updateOrCreate一些模块的使用和使用它(即)
Model::updateOrCreate($attributes = array('key' => 'value'), $values = array('key' => 'value'));
Run Code Online (Sandbox Code Playgroud)
我的问题是如何编辑上面的插入片段,以便我可以使用Model::updateOrCreate它.我的$attributes字段是'fk_workouts_id','fk_users_id','fk_exercises_id',其余部分$values将被更改.
我不知道如何实现这一点.请帮忙......
我在SwiftMailer库下的laravel中使用Mail函数.
Mail::send('mail', array('key' => $todos1), function($message) {
$message->to(array('TEST@example.com','TESsdT@example.com','TESjxfjT@example.com','TESfssdT@example.com'))->subject('Welcome!');
});
Run Code Online (Sandbox Code Playgroud)
上述功能向多个用户发送邮件,但用户知道谁将所有邮件发送为其地址所包含的
To: TEST@example.com, TESsdT@example.com, TESjxfjT@example.com, TESfssdT@example.com
Run Code Online (Sandbox Code Playgroud)
所以为了纠正这个问题,我使用了一个foreach单独发送邮件的循环
foreach($to as $receipt){
//Mail::queue('mail', array('key' => $todos1), function($message) use ($receipt)
Mail::send('mail', array('key' => $todos1), function($message) use ($receipt)
{
$message->to($receipt)->subject('Welcome!');
});
}
Run Code Online (Sandbox Code Playgroud)
上面的代码工作得很好......
我的问题是,在这个高级框架中,有任何功能可以向具有唯一to地址的用户发送邮件(即),而没有一个用户知道有多少其他人在不使用foreach...的情况下发送相同的邮件.
我没有成功尝试leftjoin并获得所需的数据
这是我的代码:
$album = Albums::->where('users_id',$user_id)
->leftJoin('photos',function($query){
$query->on('photos.albums_id','=','albums.id');
$query->where('photos.status','=',1);
// $query->limit(1);
// $query->min('photos.created_at');
})
->where('albums.status',1)->get();
Run Code Online (Sandbox Code Playgroud)
评论是我的几个尝试......
我想从照片表中只获得一张与album_id首先更新的外键相关的记录,并且状态为1
请帮忙......
我在Laravel的代码中使用过whereOr,但有时会产生不同的结果orWhere
$user_query = User::select( 'users.id', 'users.username','users.first_name','users.last_name', 'users.photo' )
->where('users.status',1)
->where('users.id','!=',$id)
->where('users.username','like','%'.$searchkey.'%')
->orWhere('users.first_name','like','%'.$searchkey.'%')
->orwhere('users.last_name','like','%'.$searchkey.'%')->get();
// ->whereOr('users.first_name','like','%'.$searchkey.'%')
// ->whereOr('users.last_name','like','%'.$searchkey.'%')->get();
Run Code Online (Sandbox Code Playgroud)
whereOr和之间的区别是什么orWhere
有没有办法touch()用于更新is_online表中字段的时间戳而不是更新laravel中的created_at字段 Eloquent ORM
目前我正在使用
User::where('id',$senderId )->update(array('is_online' => date('Y-m-d H:i:s')));
Run Code Online (Sandbox Code Playgroud) 我用过了 php artisan migrate:make add_something_to_to_user_table --table=users
和编码
Schema::table('users', function(Blueprint $table)
{
$table->string('description1');
$table->string('description2');
$table->string('description3');
});
Run Code Online (Sandbox Code Playgroud)
并添加了三个字段并将php artisan migrate字段存储到数据库中
还发现migration table用行更新了2014_11_05_145536_add_something_to_to_user_table
现在我用的时候 php artisan migrate:rollback
2014_11_05_145536_add_something_to_to_user_table迁移表中的行丢失,但添加到users表的列保持不变
为什么它不删除表中的字段也导致php artisan migrate再次使用时出错...