$followers=DB::table('user_followers as f')->join('users as u', 'u.id', '=', 'f.follower_id')->leftJoin('user_followers AS b', function($join){$join->on('b.follower_id', '=', 'f.leader_id')->on('b.leader_id', '=', 'u.id');})->selectRaw(DB::raw("u.user_id,u.full_name,u.username,u.avatar,case when b.follower_id is null then 0when b.follower_id is not null and b.status=1 then 1else 2end as isFollowing,case when b.follower_id is null then 'Follow'when b.follower_id is not null and b.status=1 then 'Pending'else 'Following'end as isFollowing"))->where("f.leader_id",$authUserId)->paginate(5);;-----------------------------------------Mysql----------------------------------SELECTu.id,u.username,f.status,case when b.follower_id is null then -- No record in b if 3 didn't follow this user back.'User is not following back'else'User is following back'end as backFROMuser_followers f -- IDs of followers of user 3INNER JOIN users u -- User information of those followersON u.id = f.follower_idLEFT JOIN user_followers b -- Check if 3 follows them back.ON b.follower_id = f.leader_id andb.leader_id = u.idWHEREf.leader_id = 582
Step 1 : php artisan make : request StoreArticleRequest Step 2 : <?php namespace App\Http\Requests; use Illuminate\Foundation\Http\FormRequest; use Illuminate\Http\JsonResponse; use Illuminate\Contracts\Validation\Validator; use Illuminate\Http\Exceptions\HttpResponseException; class StoreArticleRequest extends FormRequest { /** * Determine if the user is authorized to make this request. * * @return bool */ public function authorize () { return true ; } /** * Get the validation rules that apply to the request. * * @return array */ public function rules () { return [ 'title' => 'required' ]; } protected function failedValidation (Validator $validator ) { if ($this -> wantsJson () || $this -> ajax ()) { throw new HttpResponseException( response () -> json ([ 'status' => ...
Comments
Post a Comment