新建html 样式及js
namespace App\Admin\Extensions\Nav;
class Links
{
public function __toString()
{
return <<<HTML
<li>
<a href="" οnclick="js_method();return false;">
<i class="fa fa-floppy-o"></i>
<span class="label label-success"></span>
</a>
</li>
<script>
function js_method(){
$.ajax({
type: "GET",
dataType: "json",
url: "",
success: function (json) {
if (json.code == 1) {
toastr.success(json.message);
} else {
toastr.error(json.message);
}
},
error: function () {
toastr.warning('系统繁忙');
}
});
}
</script>
HTML;
}
}
修改模板
app/Admin/bootstrap.php
use Encore\Admin\Facades\Admin;
Admin::navbar(function (\Encore\Admin\Widgets\Navbar $navbar) {
$navbar->right(new \App\Admin\Extensions\Nav\Links());
});