-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangbao05
committed
Nov 4, 2019
1 parent
c1966c4
commit b3309df
Showing
12 changed files
with
298 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Admin\Controllers; | ||
|
||
class NoticeController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
$notices = \App\Notice::all(); | ||
return view('admin/notice/index', compact('notices')); | ||
} | ||
|
||
public function create() | ||
{ | ||
return view('admin/notice/create'); | ||
} | ||
|
||
public function store() | ||
{ | ||
$this->validate(request(), [ | ||
'title' => 'required|string', | ||
'content' => 'required|string' | ||
]); | ||
|
||
$notice = \App\Notice::create(request(['title', 'content'])); | ||
dispatch(new \App\Jobs\SendMessage($notice)); | ||
|
||
return redirect("/admin/notices"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Topic; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\App; | ||
|
||
class NoticeController extends Controller | ||
{ | ||
public function index() | ||
{ | ||
// 获取当前用户 | ||
$user = \Auth::user(); | ||
$notices = $user->notices; | ||
|
||
return view('notice/index', compact('notices')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace App\Jobs; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Queue\SerializesModels; | ||
use Illuminate\Queue\InteractsWithQueue; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Foundation\Bus\Dispatchable; | ||
|
||
class SendMessage implements ShouldQueue | ||
{ | ||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | ||
|
||
private $notice; | ||
|
||
/** | ||
* Create a new job instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(\App\Notice $notice) | ||
{ | ||
// | ||
$this->notice = $notice; | ||
} | ||
|
||
/** | ||
* Execute the job. | ||
* | ||
* @return void | ||
*/ | ||
public function handle() | ||
{ | ||
// 通知每个用户系统消息 | ||
$users = \App\User::all(); | ||
foreach ($users as $user) { | ||
$user->addNotice($this->notice); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use App\Model; | ||
|
||
class Notice extends Model | ||
{ | ||
// | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
database/migrations/2019_11_04_110156_create_notice_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateNoticeTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
// | ||
Schema::create('notices', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->string('title', 50)->default(""); | ||
$table->string('content', 1000)->default(""); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::create('user_notice', function (Blueprint $table) { | ||
$table->increments('id'); | ||
$table->integer('user_id')->default(0); | ||
$table->integer('notice_id')->default(0); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
// | ||
Schema::dropIfExists('notices'); | ||
Schema::dropIfExists('user_notice'); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
database/migrations/2019_11_04_140746_create_jobs_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class CreateJobsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('jobs', function (Blueprint $table) { | ||
$table->bigIncrements('id'); | ||
$table->string('queue'); | ||
$table->longText('payload'); | ||
$table->unsignedTinyInteger('attempts'); | ||
$table->unsignedInteger('reserved_at')->nullable(); | ||
$table->unsignedInteger('available_at'); | ||
$table->unsignedInteger('created_at'); | ||
|
||
$table->index(['queue', 'reserved_at']); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('jobs'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
@extends("admin.layout.main") | ||
|
||
@section("content") | ||
<!-- Main content --> | ||
<section class="content"> | ||
<!-- Small boxes (Stat box) --> | ||
<div class="row"> | ||
<div class="col-lg-10 col-xs-6"> | ||
<div class="box"> | ||
|
||
<!-- /.box-header --> | ||
<div class="box box-primary"> | ||
<div class="box-header with-border"> | ||
<h3 class="box-title">增加通知</h3> | ||
</div> | ||
<!-- /.box-header --> | ||
<!-- form start --> | ||
<form role="form" action="/admin/notices" method="POST"> | ||
{{csrf_field()}} | ||
<div class="box-body"> | ||
<div class="form-group"> | ||
<label for="exampleInputEmail1">标题</label> | ||
<input type="text" class="form-control" name="title"> | ||
</div> | ||
</div> | ||
<div class="box-body"> | ||
<div class="form-group"> | ||
<label for="exampleInputEmail1">内容</label> | ||
<textarea class="form-control" name="content"></textarea> | ||
</div> | ||
</div> | ||
<!-- /.box-body --> | ||
<div class="box-footer"> | ||
<button type="submit" class="btn btn-primary">提交</button> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
@extends('admin.layout.main') | ||
@section("content") | ||
|
||
<!-- Main content --> | ||
<section class="content"> | ||
<!-- Small boxes (Stat box) --> | ||
<div class="row"> | ||
<div class="col-lg-10 col-xs-6"> | ||
<div class="box"> | ||
|
||
<div class="box-header with-border"> | ||
<h3 class="box-title">通知列表</h3> | ||
</div> | ||
<a type="button" class="btn " href="/admin/notices/create">增加通知</a> | ||
<!-- /.box-header --> | ||
<div class="box-body"> | ||
<table class="table table-bordered"> | ||
<tbody> | ||
<tr> | ||
<th style="width: 10px">#</th> | ||
<th>通知名称</th> | ||
<th>操作</th> | ||
</tr> | ||
@foreach($notices as $notice) | ||
<tr> | ||
<td>{{$notice->id}}</td> | ||
<td>{{$notice->title}}</td> | ||
<td></td> | ||
</tr> | ||
@endforeach | ||
</tbody> | ||
</table> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</section> | ||
<!-- /.content --> | ||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@extends("layout.main") | ||
|
||
@section("content") | ||
|
||
<div class="col-sm-8 blog-main"> | ||
@foreach($notices as $notice) | ||
<div class="blog-post"> | ||
<p class="blog-post-meta">{{$notice->title}}</p> | ||
|
||
<p>{{$notice->content}}</p> | ||
</div> | ||
@endforeach | ||
</div><!-- /.blog-main --> | ||
|
||
|
||
@endsection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters