++++ PieModel code ++++++++++
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class PieVideo extends Model
{
protected $table="sc_pie_video";
public $timestamps =true;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'video_title', 'comment_note', 'video_file_path', 'pie_audio_id', 'pie_channel_id', 'is_publish', 'access_scope', 'created_by', 'updated_by', 'is_deleted', 'deleted_at', 'status', 'video_description', 'public_available', 'searchable'
];
public function channelName(){
return $this->hasOne('App\Models\PieChannel', 'id', 'pie_channel_id');
}
public function pieCreatedBy(){
return $this->hasOne('App\Models\User', 'id', 'created_by');
}
public function pieTags(){
return $this->hasMany('App\Models\PieVideoTags', 'video_id', 'id');
}
}
+++++ Controller code for the query result with search keyword +++++
$limit=$request->jtPageSize;
$offset=$request->jtStartIndex;
$order=isset($request->jtSorting)?$request->jtSorting:'id ASC';
$orderBy = explode(" ", $order);
$userQuery = PieVideo::with('channelName','pieTags','pieCreatedBy');
if(isset($request->status) && $request->status!=''){
$userQuery->where(function ($query) use($request){
$query->where('status',$request->status)
->where('is_deleted',0);
});
} else {
$userQuery->where(function ($query){
$query->where('is_deleted',0);
});
}
if(isset($request->keyword) && $request->keyword!=''){
$userQuery->where(function ($query) use($request){
$query->orWhere( 'video_title', 'LIKE', '%'. $request->keyword .'%')
->orWhere('id', 'LIKE', '%' . $request->keyword . '%');
});
}
$usersCountArray = $userQuery->get();
$users = $userQuery->offset($offset)->limit($limit)->orderBy($orderBy[0], $orderBy[1])->get()->toArray();
$UserCount = $usersCountArray->count();
If I want to search result with the name of users or channel title then it won't be applicable on that code. I have 4 tables Video table is a master table which data we are showing by the J table on frontend but few data has a relation which we have defined the function in video model code is attached in the 2. Provide background including what you've already tried
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire