Laravel ajax三级联动

2020-12-26 02:28

阅读:356

YPE html>

标签:cdn   成功   请求方式   三级   col   oar   use   success   name   

三级联动表:http://m.caomeipi.com/(鹏鹏)

 

路由:

//省份
Route::get(‘province‘,‘PortController@province‘);

//
Route::get(‘city‘,‘PortController@city‘);

//
Route::get(‘area‘,‘PortController@area‘);

 

控制器:

 

php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
class PortController extends Controller
{

    //查询省份
    public function province(Request $request)
    {
        $province =  DB::table(‘china_area‘)->where(‘parent_id‘,1)->get();
        return view(‘port/china‘,[‘province‘=>$province]);
    }

    //查询市
    public function city(Request $request)
    {
        $province = $request[‘province‘];
      

        $city = DB::table(‘china_area‘)->where(‘parent_id‘,‘=‘,$province)->get()->toArray();
      
         
        return json_encode([‘status‘ => 0, ‘data‘ => $city]);
    }

    //查询区
    public function area(Request $request)
    {
        $city = $request[‘city‘];
        $area = DB::table(‘china_area‘)->where(‘parent_id‘,‘=‘,$city)->get()->toArray();
        return json_encode([‘status‘ => 0, ‘data‘ => $area]);
    }
}

 

 

视图层:

Document

  

效果如图所示:

Laravel ajax三级联动

标签:cdn   成功   请求方式   三级   col   oar   use   success   name   

原文地址:https://www.cnblogs.com/fsp69/p/13919624.html


评论


亲,登录后才可以留言!