นี่เป็นแพ็คเกจแรกที่ฉันเผยแพร่ ฉันต้องการเรียนรู้วิธีสร้างแพ็คเกจง่ายๆสำหรับ Laravel ฉันได้อ่านมากมายเกี่ยวกับคอนเทนเนอร์ IOC การฉีดพึ่งพาอาศัยกันอย่างไร ... แพคเกจนี้ได้รับแรงบันดาลใจจากแพ็คเกจ 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 ' )หมายเหตุ: มันใช้โดยค่าเริ่มต้นสัญกรณ์ Bootstrap 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 อย่างที่คุณเห็นปลั๊กอินเพิ่มสองปุ่มในเซสชัน: _flashr.type และ _flashr.message