я хочу передать значение переменной в foreach, чтобы получить фиксированный объем данных
например:
$tempNum : 10;
@foreach($page_members->take($tempNum) as $page_member)
{
//code with multiple functionality
}
как сделать нажатие кнопки, это новое значение также должно учитывать $tempNum = $tempNum+10 ;
поскольку страница должна быть перезагружена с новым значением $ tempNum1
, в настоящее время я пытаюсь сделать со значением texbox, например:
<input type="text" name="outputtext" id="outputtext" value=5 />
<input type="button" name="loadmore" id="outputtext" class="loadmore btn btn-success" value="Load More" onclick="reveal(); reloadPage()"/>
@foreach($page_members->take($tempNum) as $page_member)
{
//code with multiple functionality #dont want to edit here
}
<script type="text/javascript">
var url = window.location.href;
var id = url.substring(url.lastIndexOf('#') + 1);
//console.log("id data",id);
//Get the last value
var current = parseInt(location.hash.slice(1));
//If it is set, increment it
if(current){
document.getElementById("outputtext").value = current + 5;
location.hash = '#' + (current+5);
}
function reveal() {
var val = document.getElementById("outputtext").value;
var result = parseInt(val) + parseInt(0);
document.getElementById("outputtext").value = result;
document.getElementById('outputtext').value;
// $new_value = $('#outputtext').val();
//console.log("datachcek",val);
//Set the value
location.hash = '#' + result;
}
</script>
<script>
function reloadPage(){
location.reload(true);
}
</script>
также пытался из URL-идентификатора (сохранить значение идентификатора в var), но после перехода к foreach он показывает не найден / не определен
функция контроллера
public function rolesPageSettings($username)
{
$timeline = Timeline::where('username', $username)->first();
$page = $timeline->page;
$page_members = $page->members();
$roles = Role::lists('name', 'id');
$trending_tags = trendingTags();
$theme = Theme::uses('default')->layout('default');
$theme->setTitle(trans('common.manage_roles').' '.Setting::get('title_seperator').' '.Setting::get('site_title').' '.Setting::get('title_seperator').' '.Setting::get('site_tagline'));
return $theme->scope('page/settings/roles', compact('timeline', 'page_members', 'roles', 'page','trending_tags'))->render();
}
код блейда:
@if(count($page_members) > 0)
<ul class="list-group page-likes">
<?php
$count = count($page_members);
//echo "<pre>"; print_r($count); die();
$outputtext = 5;
//$x1 = $x;
/*$x = $_GET['outputtext'];*/
//echo "<pre>"; print_r($outputtext); die();
//echo "<pre>"; print_r($x1); die();
?>
<!-- <textarea name="outputtext" id="outputtext" >5</textarea> -->
<!-- <input type="text" name="outputtext" id="outputtext" value=5 /> -->
<form class="margin-right" method="GET" action="#">
<input type="text" name="outputtext" id="outputtext" value=5 />
<input type="button" name="loadmore" id="outputtext" class="loadmore btn btn-success" value="Load More" onclick="reveal(); reloadPage()"/>
</form>
@foreach($page_members->take($outputtext) as $page_member)
@if(\Request::is('searchroleuser'))
<?php
//echo $rolepageid->id; die();
$useridroles =DB::table('users')
->select('id')
->where('timeline_id',$page_member->id)
->first();
//echo "<pre>"; print_r($useridroles); die();
$usersassigneroles = DB::table('page_user')
->select('rolecategory')
->where('user_id',$useridroles->id)
->where('page_id', $rolepageid->id)
->first();
if(!empty($usersassigneroles))
{
//
$usersassignerolesarray = explode(',',$usersassigneroles->rolecategory);
}
?>
@else
<?php
//echo $rolepageid->id; die();
$usersassigneroles = DB::table('page_user')
->select('rolecategory')
->where('user_id',$page_member->id)
->where('page_id', $rolepageid->id)
->first();
if(!empty($usersassigneroles))
{
//echo "<pre>"; print_r($usersassigneroles); die();
$usersassignerolesarray = explode(',', $usersassigneroles->rolecategory);
}
?>
@endif
<li class="list-group-item holder">
<div class="connect-list">
@if(\Request::is('searchroleuser'))
<?php
//echo "string"; die();
$imgsource = DB::table('media')
->select('source')
->where('id', $page_member->avatar_id)
->first();
// echo "<pre>"; print_r($imgsource); die();
?>
<div class="connect-link side-left">
<div class="follower">
<a href="{{ url(url($page_member->username)) }}">
<img src="<?php if($imgsource){ if(!empty($imgsource->source)){ echo 'http://kapolmitra.mukesoft.com/user/avatar/'.$imgsource->source; } else{echo 'http://kapolmitra.mukesoft.com/user/avatar/default-male-avatar.png';}} else {echo 'http://kapolmitra.mukesoft.com/user/avatar/default-male-avatar.png';}?>" alt="{{ $page_member->name }}" class="img-icon img-30" title="{{ $page_member->name }}">
{{ $page_member->name.' '.$page_member->lastname }}
</a>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4 padding-5 side-right">
<a href="#" class="btn btn-to-follow btn-default remove-pagemember remove" data-user-id="{{ $page_member->id }} - {{ $page->id }}">
<i class="fa fa-times" style="color:white"></i> {{ trans('common.remove') }}
</a>
</div>
@else
<div class="connect-link side-left">
<div class="follower">
<a href="{{ url(url($page_member->username)) }}">
<img src="{{ $page_member->avatar }}" alt="{{ $page_member->name }}" class="img-icon img-30" title="{{ $page_member->name }}">
{{ $page_member->name.' '.$page_member->lastname }}
</a>
</div>
</div>
<div class="col-md-4 col-sm-4 col-xs-4 padding-5 side-right">
<a href="#" class="btn btn-to-follow btn-default remove-pagemember remove" data-user-id="{{ $page_member->id }} - {{ $page->id }}">
<i class="fa fa-times" style="color:white"></i> {{ trans('common.remove') }}
</a>
</div>
@endif
<!-- Ashish Start -->
@if(($page->is_admin(Auth::user()->id)))
<!-- Ashish End -->
<div class="side-right follow-links">
<div class="row">
<form class="margin-right" method="POST" action="{{ url('/member/updatepage-role/') }}">
{{ csrf_field() }}
@if(\Request::is('searchroleuser'))
<?php
//echo "string"; die();
$pageuserid = DB::table('users')
->select('id')
->where('timeline_id', $page_member->timeline_id)
->first();
// echo "<pre>"; print_r($assignedroles); die();
$assignedroles = DB::table('page_user')
->select('role_id')
->where('user_id', $pageuserid->id)
->first();
?>
<?php if(!empty($assignedroles)) { ?>
<div class="col-md-5 col-sm-5 col-xs-5 padding-5">
{{ Form::select('member_role', $roles, $assignedroles->role_id , array('class' => 'form-control', 'id' => 'rolecheckbox')) }}
</div>
<?php } else { ?>
{{ Form::select('member_role', $roles,array('class' => 'form-control')) }}
<?php } ?>
@else
<div class="col-md-5 col-sm-5 col-xs-5 padding-5">
{{ Form::select('member_role', $roles, $page_member->pivot->role_id , array('class' => 'form-control', 'id' => 'rolecheckbox')) }}
</div>
@endif
<div class="col-md-5 col-sm-5 col-xs-5 padding-5" id="categorycheckbox" style="display: block;">
<table>
<?php $counter = 0;
$i = 1;
foreach($rolecategory as $rolecategory1)
{
if($counter !=0 && $counter%2 == 0){?>
</tr><tr >
<?php }?>
<td><input type="checkbox" name="categorymehul[]" value="{{$i}}"><label class="container">{{$rolecategory1->name}}<span class="checkmark"></span></label></td>
<?php $counter++;
$i++;
}
?>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<div class="col-md-3 col-sm-3 col-xs-3 padding-5">
{{ Form::submit(trans('common.assign'), array('class' => 'btn btn-to-follow btn-default')) }}
</div>
</td>
</tr>
</table>
@if(\Request::is('searchroleuser'))
<?php
$searchuserid = DB::table('users')
->select('id')
->where('timeline_id',$page_member->id)
->first();
//echo "<pre>"; print_r($searchuserid); die();
?>
{{ Form::hidden('user_id', $searchuserid->id) }}
{{ Form::hidden('page_id', $page->id) }}
@else
{{ Form::hidden('user_id', $page_member->id) }}
{{ Form::hidden('page_id', $page->id) }}
@endif
</table>
</div>
@if(\Request::is('searchroleuser'))
<?php
$searchuserid = DB::table('users')
->select('id')
->where('timeline_id',$page_member->id)
->first();
//echo "<pre>"; print_r($searchuserid); die();
?>
{{ Form::hidden('user_id', $searchuserid->id) }}
{{ Form::hidden('page_id', $page->id) }}
@else
{{ Form::hidden('user_id', $page_member->id) }}
{{ Form::hidden('page_id', $page->id) }}
@endif
</form>
</div>
</div>
@elseif(($page->is_local_admin(Auth::user()->id)))
<div class="side-right follow-links">
<div class="row">
<form class="margin-right" method="POST" action="{{ url('/member/updatepage-role/') }}">
{{ csrf_field() }}
@if(\Request::is('searchroleuser'))
<?php
$pageuserid = DB::table('users')
->select('id')
->where('timeline_id', $page_member->timeline_id)
->first();
$assignedroles = DB::table('page_user')
->select('role_id')
->where('user_id', $pageuserid->id)
->first();
//echo "<pre>"; print_r($roles); die();
?>
<?php if(!empty($assignedroles)) { ?>
<div class="col-md-5 col-sm-5 col-xs-5 padding-5">
{{ Form::select('member_role', $roles, $assignedroles->role_id, array('class' => 'form-control')) }}
</div>
<?php } else { ?>
{{ Form::select('member_role', $roles,array('class' => 'form-control')) }}
<?php } ?>
@else
<div class="col-md-5 col-sm-5 col-xs-5 padding-5">
{{ Form::select('member_role', $roles, $page_member->pivot->role_id , array('class' => 'form-control')) }}
</div>
@endif
<div class="col-md-5 col-sm-5 col-xs-5 padding-5" id="categorycheckbox" style="display: block;">
@if(Auth::user()->hasRole('gbsadmin') && $m == 4)
<table>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="1" <?php if(!empty($usersassignerolesarray)){ if(in_array("1", $usersassignerolesarray)) { echo "checked"; } }?> ><label class="container">Matrimony<span class="checkmark"></span></label></td>
<td><input type="checkbox" name="categorymehul[]" value="2" <?php if(!empty($usersassignerolesarray)){ if(in_array("2", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Editorial<span class="checkmark"></span></label></td>
</tr>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="3" <?php if(!empty($usersassignerolesarray)){ if(in_array("3", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Kapol News<span class="checkmark"></span></label></td>
<td><input type="checkbox" name="categorymehul[]" value="4" <?php if(!empty($usersassignerolesarray)){ if(in_array("4", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Literature<span class="checkmark"></span></label></td>
</tr>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="5" <?php if(!empty($usersassignerolesarray)){ if(in_array("5", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Kapol Talent<span class="checkmark"></span></label></td>
<td><input type="checkbox" name="categorymehul[]" value="6" <?php if(!empty($usersassignerolesarray)){ if(in_array("6", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">My Suggestion<span class="checkmark"></span></label></td>
</tr>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="7" <?php if(!empty($usersassignerolesarray)){ if(in_array("7", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Kapol Death<span class="checkmark"></span></label></td>
<td><input type="checkbox" name="categorymehul[]" value="8" <?php if(!empty($usersassignerolesarray)){ if(in_array("8", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Classified<span class="checkmark"></span></label></td>
</tr>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="9" <?php if(!empty($usersassignerolesarray)){ if(in_array("9", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">President's Message<span class="checkmark"></span></label></td>
<td><input type="checkbox" name="categorymehul[]" value="10" <?php if(!empty($usersassignerolesarray)){ if(in_array("10", $usersassignerolesarray)) { echo "checked"; } }?>><label class="container">General<span class="checkmark"></span></label></td>
</tr>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<div class="col-md-3 col-sm-3 col-xs-3 padding-5">
{{ Form::submit(trans('common.assign'), array('class' => 'btn btn-to-follow btn-default')) }}
</div>
</td>
</tr>
</table>
@else
<table>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="5" <?php if(!empty($usersassignerolesarray)){ if(in_array("5", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Kapol Talent<span class="checkmark"></span></label></td>
<td><input type="checkbox" name="categorymehul[]" value="3" <?php if(!empty($usersassignerolesarray)){ if(in_array("3", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">Kapol News<span class="checkmark"></span></label></td>
</tr>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="6" <?php if(!empty($usersassignerolesarray)){ if(in_array("6", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">My Suggestion<span class="checkmark"></span></label></td>
<td><input type="checkbox" name="categorymehul[]" value="10" <?php if(!empty($usersassignerolesarray)){ if(in_array("10", $usersassignerolesarray)) { echo "checked"; } }?>><label class="container">General<span class="checkmark"></span></label></td>
</tr>
<tr>
<td><input type="checkbox" name="categorymehul[]" value="9" <?php if(!empty($usersassignerolesarray)){ if(in_array("9", $usersassignerolesarray)) { echo "checked"; } } ?>><label class="container">President's Message<span class="checkmark"></span></label></td>
</tr>
<tr>
</tr>
<tr>
<td colspan="2" style="text-align: center;">
<div class="col-md-3 col-sm-3 col-xs-3 padding-5">
{{ Form::submit(trans('common.assign'), array('class' => 'btn btn-to-follow btn-default')) }}
</div>
</td>
</tr>
</table>
@endif
@if(\Request::is('searchroleuser'))
<?php
$searchuserid = DB::table('users')
->select('id')
->where('timeline_id',$page_member->id)
->first();
//echo "<pre>"; print_r($searchuserid); die();
?>
{{ Form::hidden('user_id', $searchuserid->id) }}
{{ Form::hidden('page_id', $page->id) }}
@else
{{ Form::hidden('user_id', $page_member->id) }}
{{ Form::hidden('page_id', $page->id) }}
@endif
</table>
</div>
@if(\Request::is('searchroleuser'))
<?php
$searchuserid = DB::table('users')
->select('id')
->where('timeline_id',$page_member->id)
->first();
//echo "<pre>"; print_r($searchuserid); die();
?>
{{ Form::hidden('user_id', $searchuserid->id) }}
{{ Form::hidden('page_id', $page->id) }}
@else
{{ Form::hidden('user_id', $page_member->id) }}
{{ Form::hidden('page_id', $page->id) }}
@endif
</form>
</div>
</div>
@endif
<div class="clearfix"></div>
</div>
</li>
@endforeach
</ul>
@else
<div class="alert alert-warning">
{{ trans('messages.no_members_to_admin') }}
</div>
@endif