我有一些带有PHP的选择选项,我需要将其更改为输入复选框。我将此用于作曲家消息功能,我希望有更多复选框,而不是选择多个选项。
这是我的模特:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Mailbox extends Model
{
protected $table = 'mailbox';
public $timestamps = false;
protected $fillable = [
'target_username', 'subject', 'message','date','sender_id','target_id'
];
}
这是我的控制人:
public function composeMessage(Request $request)
{
if ( $user = Sentinel::check() ) {
// return $request->all();
$data = $this->data;
$id = $user->id;
foreach ($request['target_id'] as $key => $target_id) {
$user = User::findOrfail($id);
$target = User::findOrfail($target_id);
$mailbox = Mailbox::create([
'sender_id' => $id,
'target_username' => $target->username,
'target_id' => $target->id,
'subject' => $request['subject'],
'message' => $request['message'],
'date' => strtotime(date('Y-m-d')),
]);
$log = \App\Log::create([
'user_id' => $target_id,
'log' => $request['subject'],
'date' => time(),
'type' => 'message',
'formatted_date' => date_format(date_create(date('Y-m-d')),"F dS, Y"),
'action_user_id' => $id,
'action_name' => $user->name,
'action_username' => $user->username,
'link' => url('mailbox'),
'profile_picture' => $user->profile_picture
]);
}
}
if ($mailbox != "") {
flash(trans('Your message has been sent'), 'success');
} else {
flash(trans('Your message has been not sent'), 'warning');
}
return \Redirect::route('mailbox')
->with( 'tabname','inbox' );
}
else{
return redirect('home');
}
}
如何将其更改为输入复选框?
<section>
<label class="input">
<label class="select">
<select name="role" id="role" style="width:100%">
<option value="">Select Role</option>
<option selected value="1" <?php if(isset($replyMessage)){if($role_id->role_id == 1){ echo "selected"; } } ?>>Individuals</option>
<option value="100" <?php if(isset($replyMessage)){if($role_id->role_id == 100){ echo "selected"; } }?>>Organizations</option>
</select>
<section>
<label class="input">
<label class="select">
<select name="target_id[]" id="target_user" class="target_user" style="width:100%" multiple="multiple">
@if(!isset($replyMessage))
@foreach($users->contact as $user)
<option value="{{ $user->id }}" <?php if(isset($replyMessage)){ if($replyMessage == $user->id) { echo "selected"; } } ?>>{{ $user->username }}
</option>
@endforeach
@endif
</select>
</label>
</label>
</section>
这是我尝试过的:
<section>
<label class="select">
<select name="target_id[]" id="target_user" class="target_user" style="width:100%" multiple="multiple">
@if(!isset($replyMessage))
@foreach($users->contact as $user)
<input type="checkbox" value="{{ $user->id }}" <?php if(isset($replyMessage)){ if($replyMessage == $user->id) { echo "selected"; } } ?>>{{ $user->username }}>
@endforeach
@endif
</label>
</section>
答案 0 :(得分:1)
简单地完全删除选择元素并添加输入复选框
<section>
<label class="select">
@if(!isset($replyMessage))
@foreach($users->contact as $user)
<input name="target_id[]" type="checkbox" value="{{ $user->id }}" <?php if(isset($replyMessage)){ if($replyMessage == $user->id) { echo "selected"; } } ?>>{{ $user->username }}
@endforeach
@endif
</label>
</section>