目前我创建了一个单一的输入字段“ id”,如果输入有效的id显示学生(姓名,电子邮件,ID)。这是完美的工作。
现在我要添加另一个输入的“加入日期”
在此功能中,我要检查输入“ id”和“加入日期”的内容是马赫,然后在视图中显示学生数据,否则显示(“未找到数据”)消息
我的观点
<form action="/search" method="POST" role="search">
{{ csrf_field() }}
<div class="input-group">
<input type="text" class="form-control" name="id"
placeholder="Search users">
<span class="input-group-btn">
<button type="submit" class="btn btn-default">
<span class="glyphicon glyphicon-search"></span>
</button>
</span>
</div>
</form>
<div class="container">
@if(isset($details))
<p> The Search results for your query <b> </b> are :</p>
<h2>Sample User details</h2>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>id</th>
<th>Photo</th>
<th>certificate_approval</th>
</tr>
</thead>
<tbody>
@foreach($details as $user)
<tr>
<td>{{$user->student_name}}</td>
<td>{{$user->email}}</td>
<div class="card-body">
<img src="STUDENT_DATA/STUDENT_PHOTO/{{ $user->student_photo }}" class="img-circle" width="90" />
</div>
<td>{{$user->student_registration_id}}</td>
<td>{{$user->student_certificate_approval}}</td>
</tr>
@endforeach
</tbody>
</table>
@elseif(isset($message))
<p>{{$message}}</p>
@endif
</div>
我的路线
use App\Student;
use Illuminate\Support\Facades\Input;
Route::any( '/search', function(){
$id = Input::get( 'id' );
if($id != ""){
$user = Student::where( 'student_registration_id', 'LIKE', '%' . $id . '%' )->get();
if (count ( $user ) > 0)
return view( 'my-search' )->withDetails( $user )->withQuery($id);
}
return view ( 'my-search' )->withMessage ( "No Details found!" );
} );
我的模型
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Database\Eloquent\Model;
class Student extends Model
{
protected $table = 'student_lists';
protected $fillable = ['student_name', 'student_registration_id', 'date_of_join', 'student_phone_no', 'student_photo', ];
}
正如您所说的“输入IDand
的加入日期”。两者都匹配,然后显示学生详细信息。
$user = Student::where( 'student_registration_id', 'LIKE', '%' . $id . '%' )
->where('date_of_join', 'LIKE', '%' . $date_of_join . '%')
->where('approved', 'APPROVE')
->get();
if(!empty($user)){
return view( 'my-search' )->withDetails( $user )->withQuery($id);
} else {
return view ( 'my-search' )->withMessage ( "No Details found!" );
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句