laravel框架之关注/取消关注

以下为控制器部分代码

/**
	*显示我的粉丝及我的关注
	*@param $fan我的粉丝
	*@param $follow我的关注(两表联查)
	*/
	public function fans(){

		$fans = Login::fans();

		$follow = Login::followshow();

		$count = count($follow);
		return view('Fans/fans_show',['fans'=>$fans,'follow'=>$follow,'count'=>$count]);
	}

	//关注
	public function insert(){

		$info = Input::get();

		$res = Login::insertFollow($info);

		echo $res;

	}

	//取消关注
	public function delfans(){

		$info = Input::get('id');

		$res = Login::fandel($info);

		echo $res;
	}

以下为模型中部分代码

//显示我的粉丝
	public static function fans(){

		$res = DB::table('jy_fans')->get();

		return $res;
	}

	//我的关注
	public static function followshow(){

		$uid = Session::get('id');
		
		$sql = "select * from jy_follow inner join jy_fans on jy_follow.fid = jy_fans.fid where jy_follow.uid = $uid";

		$result = DB::select($sql);

		return $result;
	}

	//点击关注实现入库
	public static function insertFollow($arr){
		//print_r($arr);die;
		$uid = Session::get('id');

		$array = array(

			'uid' => $uid,

			'fid' => $arr['id']
		);
		$res = DB::table('jy_follow')->insert($array);

		return $res;
	}

	//取消关注
	public static function fandel($id){

		$res = DB::table('jy_follow')->where('id',$id)->delete();

		return $res;
	}

下面为模板代码



    
        
        我的好友
        
        
        
        
        
        
        
    
    

        
我的好友

你可能感兴趣的:(tp5)