您的位置 >>> 星想互联 >>> 编程技术 >>> PHP高级编程
laravel 取栏目下对应的文章
点击数:436  发布时间2018-11-21 15:38:36


namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use DB;
use App\Model\model_news;

class index extends Controller{
    public function index(){
        $rs=DB::table('newstype')->orderby('typeid')->get();
        $con=[];

        foreach($rs as $v){
            $db=DB::table('news')->where('typeid','=',$v->typeid)->get();
            $con[]=$db;
        }

        foreach($rs as $k=>$v){
            echo $v->typename;
            echo "<br>";
            foreach($con[$k] as $m){
                echo $m->title;
            }
            
            echo "<hr>";

        }
    }
}
来源:咸宁网站建设