1
0
Moell 9 жил өмнө
parent
commit
685204c67a

+ 113 - 0
app/Http/Controllers/Backend/LinkController.php

@@ -0,0 +1,113 @@
+<?php
+
+namespace App\Http\Controllers\Backend;
+
+use Illuminate\Http\Request;
+
+use App\Http\Requests;
+use App\Http\Controllers\Controller;
+use App\Http\Requests\Backend\Link\CreateRequest;
+use App\Http\Requests\Backend\Link\UpdateRequest;
+use App\Repositories\LinkRepositoryEloquent;
+
+class LinkController extends Controller
+{
+    protected $link;
+
+    public function __construct(LinkRepositoryEloquent $link)
+    {
+        $this->link = $link;
+    }
+
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        $links = $this->link->all();
+        return view('backend.link.index', compact('links'));
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        return view('backend.link.create');
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(CreateRequest $request)
+    {
+        if ($this->link->create($request->all())) {
+            return redirect('backend/link')->with('success', '友情链接添加成功');
+        }
+        return redirect()->back()->withErrors('系统异常,友情链接添加失败');
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function show($id)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function edit($id)
+    {
+        $link = $this->link->find($id);
+        return view('backend.link.edit', compact('link'));
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function update(UpdateRequest $request, $id)
+    {
+        $link = $this->link->find($id);
+        if ($link) {
+            if ($this->link->update($request->all(), $id)) {
+                return redirect('backend/link')->with('success', '友情链接添加成功');
+            }
+        }
+        return redirect()->back()->withErrors('系统异常,修改友情链接失败');
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  int  $id
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy($id)
+    {
+        if ($this->link->find($id)) {
+            if ($this->link->delete($id)) {
+                return response()->json(['status' => 0]);
+            }
+        }
+        return response()->json(['status' => 1]);
+    }
+}

+ 40 - 0
app/Http/Requests/Backend/Link/CreateRequest.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Http\Requests\Backend\Link;
+
+use App\Http\Requests\Request;
+
+class CreateRequest extends Request
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'name'  => 'required',
+            'url'   => 'required|url'
+        ];
+    }
+
+    public function messages()
+    {
+        return [
+            'name.required' => '友情链接名字不能为空',
+            'url.required'  => 'URL不能为空',
+            'url.url'       => '请输入合法的URL'
+        ];
+    }
+}

+ 40 - 0
app/Http/Requests/Backend/Link/UpdateRequest.php

@@ -0,0 +1,40 @@
+<?php
+
+namespace App\Http\Requests\Backend\Link;
+
+use App\Http\Requests\Request;
+
+class UpdateRequest extends Request
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     *
+     * @return bool
+     */
+    public function authorize()
+    {
+        return true;
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules()
+    {
+        return [
+            'name'  => 'required',
+            'url'   => 'required|url'
+        ];
+    }
+
+    public function messages()
+    {
+        return [
+            'name.required' => '友情链接名字不能为空',
+            'url.required'  => 'URL不能为空',
+            'url.url'       => '请输入合法的URL'
+        ];
+    }
+}

+ 1 - 0
app/Http/routes.php

@@ -29,5 +29,6 @@ Route::group(['prefix'=>'backend'], function(){
         Route::resource('category', 'Backend\CategoryController');
         Route::resource('user', 'Backend\UserController');
         Route::resource('tag', 'Backend\TagController');
+        Route::resource('link', 'Backend\LinkController');
     });
 });

+ 15 - 0
app/Models/Link.php

@@ -0,0 +1,15 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Prettus\Repository\Contracts\Transformable;
+use Prettus\Repository\Traits\TransformableTrait;
+
+class Link extends Model implements Transformable
+{
+    use TransformableTrait;
+
+    protected $fillable = ['name','url','sequence'];
+
+}

+ 14 - 0
app/Repositories/LinkRepository.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace App\Repositories;
+
+use Prettus\Repository\Contracts\RepositoryInterface;
+
+/**
+ * Interface LinkRepository
+ * @package namespace App\Repositories;
+ */
+interface LinkRepository extends RepositoryInterface
+{
+    //
+}

+ 36 - 0
app/Repositories/LinkRepositoryEloquent.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace App\Repositories;
+
+use Prettus\Repository\Eloquent\BaseRepository;
+use Prettus\Repository\Criteria\RequestCriteria;
+use App\Repositories\LinkRepository;
+use App\Models\Link;
+use App\Validators\LinkValidator;
+
+/**
+ * Class LinkRepositoryEloquent
+ * @package namespace App\Repositories;
+ */
+class LinkRepositoryEloquent extends BaseRepository implements LinkRepository
+{
+    /**
+     * Specify Model class name
+     *
+     * @return string
+     */
+    public function model()
+    {
+        return Link::class;
+    }
+
+    
+
+    /**
+     * Boot up the repository, pushing criteria
+     */
+    public function boot()
+    {
+        $this->pushCriteria(app(RequestCriteria::class));
+    }
+}

+ 33 - 0
database/migrations/2016_08_31_143604_create_links_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateLinksTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('links', function (Blueprint $table) {
+            $table->increments('id');
+            $table->string('name');
+            $table->string('url');
+            $table->smallInteger('sequence');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::drop('links');
+    }
+}

+ 33 - 0
database/migrations/2016_08_31_144116_create_links_table.php

@@ -0,0 +1,33 @@
+<?php
+
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Database\Migrations\Migration;
+
+class CreateLinksTable extends Migration
+{
+
+	/**
+	 * Run the migrations.
+	 *
+	 * @return void
+	 */
+	public function up()
+	{
+		Schema::create('links', function(Blueprint $table) {
+            $table->increments('id');
+
+            $table->timestamps();
+		});
+	}
+
+	/**
+	 * Reverse the migrations.
+	 *
+	 * @return void
+	 */
+	public function down()
+	{
+		Schema::drop('links');
+	}
+
+}

+ 28 - 0
public/js/backend.js

@@ -164,4 +164,32 @@ $(function() {
         $("#tag-form")[0].reset();
     });
 
+    $("#link-form").bootstrapValidator({
+        validatorDefaultParam,
+        fields : {
+            name: {
+                validators: {
+                    notEmpty: {
+                        message: "请输入链接名"
+                    }
+                }
+            },
+            url : {
+                validators: {
+                    notEmpty: {
+                        message: "URL不能为空"
+                    },
+                    uri: {
+                        message: '请输入合法的URL地址'
+                    }
+                }
+            }
+        }
+    });
+
+    $("#link-form #reset-btn").click(function(){
+        $("#link-form").data('bootstrapValidator').resetForm(true);
+        $("#link-form")[0].reset();
+    });
+
 });

+ 56 - 0
resources/views/backend/link/create.blade.php

@@ -0,0 +1,56 @@
+@extends('layouts.backend')
+
+@section('title', '友情链接添加')
+
+@section('header')
+    <h1>
+        友情链接添加
+    </h1>
+@endsection
+
+@section('content')
+    <div class="row">
+        <div class="col-xs-12">
+            @include('backend.alert.warning')
+            <div class="box box-solid">
+                <form role="form" method="post" action="{{ url('backend/link') }}" id="link-form">
+                    <div class="box-body">
+                        <div class="form-group">
+                            <label for="name">链接名称</label>
+                            <div class="row">
+                                <div class='col-md-6'>
+                                    <input type='text' class='form-control' name="name" id='name' placeholder='请输入链接名称'>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="form-group">
+                            <label for="url">URL</label>
+                            <div class="row">
+                                <div class='col-md-6'>
+                                    <input type='text' class='form-control' name="url" id='url' placeholder='请输入以http或https合法的链接'>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="form-group">
+                            <label for="sequence">顺序</label>
+                            <div class="row">
+                                <div class='col-md-6'>
+                                    <input type='text' class='form-control' name="sequence" id='sequence' placeholder='请输入链接顺序'>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+
+                    {{ csrf_field() }}
+
+
+                    <div class="box-footer">
+                        <button type="submit" class="btn btn-primary">确定</button>
+                        <button type="button" class="btn btn-warning" id="reset-btn">重置</button>
+                    </div>
+                </form>
+            </div>
+            <!-- /.box -->
+        </div>
+    </div>
+@endsection

+ 56 - 0
resources/views/backend/link/edit.blade.php

@@ -0,0 +1,56 @@
+@extends('layouts.backend')
+
+@section('title', '友情链接修改')
+
+@section('header')
+    <h1>
+        友情链接修改
+    </h1>
+@endsection
+
+@section('content')
+    <div class="row">
+        @include('backend.alert.warning')
+        <div class="col-xs-12">
+            <div class="box box-solid">
+                <form role="form" method="post" action="{{ route('backend.link.update', ['id' => $link->id]) }}" id="link-form">
+                    <div class="box-body">
+                        <div class="form-group">
+                            <label for="name">链接名称</label>
+                            <div class="row">
+                                <div class='col-md-6'>
+                                    <input type='text' value={{ $link->name }} class='form-control' name="name" id='name' placeholder='请输入链接名称'>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="form-group">
+                            <label for="url">URL</label>
+                            <div class="row">
+                                <div class='col-md-6'>
+                                    <input type='text' value={{ $link->url }} class='form-control' name="url" id='url' placeholder='请输入以http或https合法的链接'>
+                                </div>
+                            </div>
+                        </div>
+                        <div class="form-group">
+                            <label for="sequence">顺序</label>
+                            <div class="row">
+                                <div class='col-md-6'>
+                                    <input type='text' value="{{ $link->sequence }}" class='form-control' name="sequence" id='sequence' placeholder='请输入链接顺序'>
+                                </div>
+                            </div>
+                        </div>
+                    </div>
+
+                    {{ csrf_field() }}
+                    {{ method_field('PUT') }}
+
+                    <div class="box-footer">
+                        <button type="submit" class="btn btn-primary">确定</button>
+                        <button type="button" class="btn btn-warning" id="reset-btn">重置</button>
+                    </div>
+                </form>
+            </div>
+            <!-- /.box -->
+        </div>
+    </div>
+@endsection

+ 66 - 0
resources/views/backend/link/index.blade.php

@@ -0,0 +1,66 @@
+@extends('layouts.backend')
+
+@section('title', '友情链接')
+
+@section('header')
+    <h1>
+        友情链接
+    </h1>
+@endsection
+
+@section('content')
+    <div class="row">
+        <div class="col-xs-12">
+            @include('backend.alert.success')
+            <div class="box box-solid">
+                <!-- /.box-header -->
+                <div class="box-header">
+                    <div class="pull-right">
+                        <div class="btn-group">
+                            <a href="{{ route('backend.link.create') }}" class="btn btn-white tooltips"
+                               data-toggle="tooltip" data-original-title="新增"><i
+                                        class="glyphicon glyphicon-plus"></i></a>
+                        </div>
+                    </div><!-- pull-right -->
+                </div>
+                <div class="box-body table-responsive no-padding ">
+                    <table class="table table-hover">
+                        <tr>
+                            <th>名字</th>
+                            <th>排序</th>
+                            <th>URL</th>
+                            <th>操作</th>
+                        </tr>
+                        @if ($links)
+                            @foreach($links as $link)
+                                <tr>
+                                    <td>{{ $link->name }}</td>
+                                    <td>{{ $link->sequence }}</td>
+                                    <td>{{ $link->url }}</td>
+                                    <td>
+                                        <a href='{{ route("backend.link.edit", ["id" => $link->id]) }}' class='btn btn-info btn-xs'>
+                                            <i class="fa fa-pencil"></i> 修改</a>
+                                        <a data-href='{{ route("backend.link.destroy", ["id" => $link->id]) }}'
+                                           class='btn btn-danger btn-xs link-delete'><i class="fa fa-trash-o"></i> 删除</a>
+                                    </td>
+                                </tr>
+                            @endforeach
+                        @endif
+                    </table>
+                </div>
+            </div>
+            <!-- /.box -->
+        </div>
+    </div>
+@endsection
+
+@section('javascript')
+    <script>
+        $(function() {
+            $(".link-delete").click(function(){
+                var url = $(this).attr('data-href');
+                Moell.ajax.delete(url);
+            });
+        });
+    </script>
+@endsection

+ 1 - 1
resources/views/layouts/backend.blade.php

@@ -205,7 +205,6 @@
                         <li><a href="{{ url('backend/article') }}">文章管理</a></li>
                         <li><a href="{{ url('backend/article/create') }}">发布文章</a></li>
                         <li><a href="{{ url('backend/category') }}">文章分类</a></li>
-                        <li><a href="{{ url('backend/tag') }}">文章标签</a></li>
                     </ul>
                 </li>
                 <li>
@@ -255,6 +254,7 @@
                     </a>
                     <ul class="treeview-menu">
                         <li><a href="{{ url('backend/setting') }}">博客设置</a></li>
+                        <li><a href="{{ url('backend/link') }}">友情链接</a></li>
                     </ul>
                 </li>