flashr
v1.0.1
これは私の初めてのパッケージです。 Laravelのためのシンプルなパッケージを作る方法を学びたかったのです。私はIOCコンテナ、Laravelが依存関係の噴射などをどのように行うかについて多くのことを読んでいます...このパッケージは、Great Laracasts/Flashパッケージに触発されました!
走る
$ composer require linking/flashr
パッケージがインストールされている場合、Laravel 5.xを実行している場合は、このようなAppServiceProviderにパッケージを登録できます。
<?php
use Linking Flashr FlashrServiceProvider ;
use Illuminate Support ServiceProvider ;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot ()
{
// ...
$ this -> app -> register (FlashrServiceProvider::class);
}
} Laravelの古いバージョンを実行している場合は、 app.phpファイルを編集して、 providersオプションにこれを追加できます
' providers ' => [
// ...
Linking Flashr FlashrServiceProvider::class,
];また、ファイルApp.phpに「エイリアス」キーの下にファサードを追加する必要があります。
' aliases ' => [
// ..
' Flashr ' => Linking Flashr Facades Flashr::class,
// ..
];コントローラー内では、できます
public function edit ( Post $ post ) {
Flashr:: success ( " The post has been edited " );
return view ( ' post.edit ' , compact ( ' post ' ));
}FlashRは、異なるタイプのフラッシュを印刷するために異なる関数を公開します。 FlashR関数のリストは次のとおりです。
Flashr::success($message)Flashr::info($message)Flashr::warning($message)Flashr::danger($message)次に、あなたの見解では、ベンダービューを含めることができます。
@include ( ' flashr::flashes ' )注:デフォルトでは、Twitterブートストラップ表記を使用します。この動作を交換したい場合は、次の動作を読んでください
ビューをカスタマイズしたい場合は、単に実行してください
php artisan vendor:publish --tag=flashr
次に、ビューディレクトリに移動します。ベンダーディレクトリを見つける必要があります。このディレクトリ内では、 FlashRディレクトリがこちらになります。このファイルを必要なものに編集できます。デフォルトでは、ファイルは次のようになります。
@php
$flashr_type = Session :: has ( ' _flashr.type ' ) ? Session :: get ( ' _flashr.type ' ) : null ;
$flashr_message = Session :: has ( ' _flashr.message ' ) ? Session :: get ( ' _flashr.message ' ) : null ;
@endphp
@if ( $flashr_type && $flashr_message )
< div style = " position : relative " class = " alert alert- {{ $flashr_type } } " role = " alert " >
{{ $flashr_message } }
< span id = " close-flash " onclick = " var el = this.parentElement; el.remove() "
style = " position : absolute ; top : 10 px ; right : 10 px ; font-size : 24 px ; line-height : 10 px ; cursor : pointer " > & times ; </ span >
</ div >
@endifご覧のとおり、プラグインはセッションに2つのキーを追加します: _flashr.typeと_flashr.message