1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【laravel-admin】【controller】javascript

Last updated at Posted at 2020-10-06

##laravel-adminのController側でjavascriptを使う

ちょっとしたjavascriptのためにいちいちファイルを作って、とかviewを変更して、とかが大変な時は以下の方法でcontroller側にjavascriptを書いてページに埋め込むことができます。
viewの一部を変更したいけどviewには手を加えたくない...という場合などに便利です。

SampleController.php
use Encore\Admin\Admin;

class SampleController extends AdminController
{
    /**
     * sample
     */
    public function sample(Content $content)
    {
        $script = <<<SCRIPT
$('.breadcrumb li:first').remove();
$('.breadcrumb .active').html('<i class="fa fa-home"></i>メニュー');
$('.navbar-custom-menu').find('.pull-left').html('');
$('.main-footer').find('strong').html('');
SCRIPT;
        Admin::script($script);
        Admin::style('.form-control {margin-top: 10px;}');
        return $content
        ->title('メニュー')
        ->description('メニューです。')
     ->row('メニュー1')
        ->row('メニュー2')
        ->row('メニュー3');
    }
}

1行目→パンくずリストの1つ目を削除
2行目→自身がいる位置を現在地として表示
3行目→ユーザー設定のボタンを削除
4行目→フッターの文字を削除
こっちはcss→Admin::style('.form-control {margin-top: 10px;}');

参考:Laravel admin | CSS / JavaScript

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?