您好,登錄后才能下訂單哦!
怎么在laravel中安裝yajra插件?針對這個問題,這篇文章詳細介紹了相對應的分析和解答,希望可以幫助更多想解決這個問題的小伙伴找到更簡單易行的方法。
命令行cd進入項目根目錄下,執行
composer require yajra/laravel-datatables-oracle
安裝yajra datatables軟件包
打開config/app.php文件,修改providers和aliases配置
'providers' => [ .... Yajra\DataTables\DataTablesServiceProvider::class, ] 'aliases' => [ .... 'DataTables' => Yajra\DataTables\Facades\DataTables::class, ]
view的創建
<!DOCTYPE html> <html lang="{{ str_replace('_', '-', app()->getLocale()) }}"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Laravel-datatable</title> <!-- Fonts --> <link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap" rel="external nofollow" rel="stylesheet"> <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/dt/dt-1.10.23/datatables.min.css" rel="external nofollow" /> <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script> <script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.23/datatables.min.js"></script> <style> body { font-family: 'Nunito'; } </style> </head> <body class="antialiased"> {{\Carbon\Carbon::now()}} <table id="example"> <thead> <tr> <th></th> <th>姓名</th> <th>生日</th> <th>性別</th> <th>工作</th> <th>電話</th> <th>郵箱</th> <th>地址</th> </tr> </thead> </table> </body> <script> $(document).ready(function (){ let datatable = $('#example').DataTable({ searching:false, paging:false, ajax:{ url:"{{route('getData')}}", }, columns:[ { data:"id", name:"id", }, { data:"name", name:"name", }, { data:"birthday", name:"birthday", }, { data:"sex", name:"sex", }, { data:"job", name:"job", }, { data:"tel", name:"tel", }, { data:"email", name:"email", }, { data:"address", name:"address", }, ], }); }); </script> </html>
cmd執行
php artisan make:controller DatatableController
設定路由并編輯控制器
//web.php文件 Route::get('/datatable',[App\Http\Controllers\DatatableController::class,'index']); Route::get('/datatable',[App\Http\Controllers\DatatableController::class,'getData'])->name('getData'); //控制器 <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; class DatatableController extends Controller { public function index(){ return view('welcome'); } public function getData(){ $datas = DB::table('user')->select('*')->get(); return datatables()->of($datas) ->editColumn('id', '<input type="hidden" value="{{$id}}"><input type="checkbox" name="select">')->editColumn('name', '{{$name}}') ->editColumn('birthday', '{{$birthday}}')->editColumn('sex', '{{$sex}}') ->editColumn('job', '{{$job}}')->editColumn('tel', '{{$tel}}') ->editColumn('email', '{{$email}}')->editColumn('address', '{{$address}}') ->escapeColumns([])->make(true); } }
關于怎么在laravel中安裝yajra插件問題的解答就分享到這里了,希望以上內容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關注億速云行業資訊頻道了解更多相關知識。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。