i have few simple code and i wanna paginate when my condition is correct
我有几个简单的代码,我想在我的条件正确时分页
here my codes
这是我的代码
Route:
Route::resource('lang','zabanController');
Controller :
public function index(){
$show=DB::table('zaban')->paginate(5);
return view('twoLang.index',compact('show'));
}
public function show($id)
{
DB::table('zaban')->where('default_lang','!=',$id)->update([
'default_lang'=>$id
]);
}
View :
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div>
<a href="{{action('zabanController@show',1)}}">Per</a>
<a href="{{action('zabanController@show',0)}}">ENG</a>
</div>
<table class="table table-hover table-bordered table-striped">
<thead>
<tr>
<th>id</th>
<th>lang ID</th>
<th>Default lang</th>
<th>Content</th>
</tr>
</thead>
<tbody>
@foreach($show as $content)
@if($content->my_lang==$content->default_lang)
<tr>
<th>{{$content->id}}</th>
<th>{{$content->my_lang}}</th>
<th>{{$content->default_lang}}</th>
<th>{{$content->content}}</th>
</tr>
@endif
@endforeach
</tbody>
</table>
{{$show->links()}}
</div>
</div>
</div>
DB -> Table Name 'zaban'
DB - >表名'zaban'
table Fields => id , my_lang , default_lang ,created_at , updated_at
table Fields => id,my_lang,default_lang,created_at,updated_at
and here my problem
这是我的问题
i wanna paginate content that 'my_lang' = 'default_lang'
我想分页'my_lang'='default_lang'的内容
just like this
像这样
id = 1 , my_lang = 0 , default_lang = 1
id = 1,my_lang = 0,default_lang = 1
id = 2 , my_lang = 1 , default_lang = 1
id = 2,my_lang = 1,default_lang = 1
id = 3 , my_lang = 0 , default_lang = 1
id = 3,my_lang = 0,default_lang = 1
ok.here just need return id=2
好的,只需要返回id = 2
ofcourse default_lang may change in process but my_lang always is fix (if i wrote correct :) )
ofcourse default_lang可能会在进程中发生变化,但my_lang总是修复(如果我写的正确:))
meaning if table field change like this :
表示如果表字段改变如下:
id = 1 , my_lang = 0 , default_lang = 0
id = 1,my_lang = 0,default_lang = 0
id = 2 , my_lang = 1 , default_lang = 1
id = 2,my_lang = 1,default_lang = 1
id = 3 , my_lang = 0 , default_lang = 0
id = 3,my_lang = 0,default_lang = 0
need to return id=1 and id=3
需要返回id = 1和id = 3
hope clear my mind
希望清楚我的想法
i wrote this in my controller but no chance
我在我的控制器中写了这个,但没有机会
$show=DB::table('zaban')->where('my_lang','default_lang')->paginate(5);
and this
$alls=DB::table('zaban')->get();
foreach($alls as $al)
{
$show = DB::table('zaban')->where('my_lang','default_lang')->paginate(5);
}
1 个解决方案
#1
2
In your query you search string 'default_lang' in 'my_lang' column that is why you get an empty collection. You can orderBy
default_lang:
在您的查询中,您在'my_lang'列中搜索字符串'default_lang',这就是您获得空集合的原因。你可以orderBy default_lang:
$show=DB::table('zaban')->orderBy('default_lang')->paginate(5);
Or select 'default_lang' where value is 'some value ...':
或者选择'default_lang',其中value是'some value ...':
$show=DB::table('zaban')->where('default_lang','some value ...')->paginate(5);
If you want verify that two columns are equal:
如果要验证两列是否相等:
$show = DB::table('zaban')
->whereColumn('my_lang', 'default_lang')
->paginate(5);
#1
2
In your query you search string 'default_lang' in 'my_lang' column that is why you get an empty collection. You can orderBy
default_lang:
在您的查询中,您在'my_lang'列中搜索字符串'default_lang',这就是您获得空集合的原因。你可以orderBy default_lang:
$show=DB::table('zaban')->orderBy('default_lang')->paginate(5);
Or select 'default_lang' where value is 'some value ...':
或者选择'default_lang',其中value是'some value ...':
$show=DB::table('zaban')->where('default_lang','some value ...')->paginate(5);
If you want verify that two columns are equal:
如果要验证两列是否相等:
$show = DB::table('zaban')
->whereColumn('my_lang', 'default_lang')
->paginate(5);