Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete index's search function #2

Open
wants to merge 5 commits into
base: dev-master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions app/Http/Controllers/ActivityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,21 @@
use Illuminate\Http\Request;
use App\Activity;
use Auth;
use Illuminate\Support\Facades\Input;

class ActivityController extends Controller
{
/**
* Activity List Page
* Activity List Page And Search
*/
public function index()
{
$exhibits = Activity::inRandomOrder()->limit(3)->get();
$activities = Activity::latest()->paginate(12);
if (Input::get('q') !== null) {
$activities = Activity::where('title', 'like', '%'.Input::get('q').'%')->latest()->paginate(12);
} else {
$activities = Activity::latest()->paginate(12);
}

return view('activity.index', compact('activities', 'exhibits'));
}
Expand Down
48 changes: 48 additions & 0 deletions app/Http/Controllers/Admin/ActivityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Created by PhpStorm.
* User: kavience
* Date: 18-3-17
* Time: 下午4:18
*/

namespace App\Http\Controllers\Admin;


use App\Activity;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

class ActivityController extends Controller
{
/**
* Activities list and search
*/
public function index()
{
if (Input::get('q')!==null) {
$activityModel = new Activity();
$activities = $activityModel->where('title', 'like', '%'.Input::get('q').'%')->paginate();
} else {
$activities = Activity::latest()->paginate();
}

return view('admin.activities.index', compact('activities'));
}

/**
* Activities delete
*/
public function destroy(Request $request)
{
$this->validate($request, [
'id' => 'required|integer',
]);

Activity::destroy($request->id);
flash('操作成功');

return back();
}
}
48 changes: 48 additions & 0 deletions app/Http/Controllers/Admin/NewsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* Created by PhpStorm.
* User: kavience
* Date: 18-3-17
* Time: 下午2:49
*/

namespace App\Http\Controllers\Admin;


use App\Http\Controllers\Controller;
use App\News;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

class NewsController extends Controller
{
/**
* News list and search
*/
public function index()
{
if (Input::get('q')!==null) {
$newsModel = new News();
$news = $newsModel->where('title', 'like', '%'.Input::get('q').'%')->paginate();
} else {
$news = News::latest()->paginate();
}

return view('admin.news.index', compact('news'));
}

/**
* News delete
*/
public function destroy(Request $request)
{
$this->validate($request, [
'id' => 'required|integer',
]);

News::destroy($request->id);
flash('操作成功');

return back();
}
}
11 changes: 9 additions & 2 deletions app/Http/Controllers/Admin/TopicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
use App\Topic;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;

class TopicController extends Controller
{
/**
* Topic list page
* Topic list and search
*/
public function index()
{
$topics = Topic::latest()->paginate();
if (Input::get('q')!==null) {
$TopicModel = new Topic();
$topics = $TopicModel->where('title', 'like', '%'.Input::get('q').'%')->paginate();
} else {
$topics = Topic::latest()->paginate();
}

return view('admin.topic.index', compact('topics'));
}

}
10 changes: 8 additions & 2 deletions app/Http/Controllers/NewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

use App\News;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;

class NewsController extends Controller
{
/**
* News Index Page
* News Index Page And Search
*/
public function index()
{
$news = News::latest()->paginate();
if (Input::get('q')!==null) {
$newsModel = new News();
$news = $newsModel->where('title', 'like', '%'.Input::get('q').'%')->paginate();
} else {
$news = News::latest()->paginate();
}

return view('news.index', compact('news'));
}
Expand Down
11 changes: 9 additions & 2 deletions app/Http/Controllers/TopicController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
use App\TopicNode;
use App\TopicThumb;
use App\TopicFavorite;
use Illuminate\Support\Facades\Input;

class TopicController extends Controller
{
/**
* Topic List Page
* Topic List Page And Search
*/
public function index(Request $request)
{
Expand Down Expand Up @@ -53,7 +54,13 @@ public function index(Request $request)
}
}

$topics = $query->latest()->paginate(10);
if (Input::get('q') !== null) {
$topics = $query->where('title', 'like', '%'.Input::get('q').'%')->
latest()->paginate(10);

} else {
$topics = $query->latest()->paginate(10);
}
$rootNodes = TopicNode::roots()->with('childNodes')->get();

return view('topic.index', compact('topics', 'rootNodes'));
Expand Down
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@
'Validator' => Illuminate\Support\Facades\Validator::class,
'View' => Illuminate\Support\Facades\View::class,

//
'Input' => \Illuminate\Support\Facades\Input::class,

//
'Image' => Intervention\Image\Facades\Image::class,
Expand Down
6 changes: 6 additions & 0 deletions resources/views/activity/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
活动 - {{ $system->site_title }}
@endsection

@section('search')
<form class="form-inline float-right d-none d-md-flex" action="{{ route('activity.index') }}">
<input class="form-control" type="text" data-action="grow" placeholder="搜索" name="q" value="{{ Input::get('q') }}">
</form>
@endsection

@section('mainBody')
<div id="section-mainbody" class="page-activity-index">
<!--
Expand Down
94 changes: 94 additions & 0 deletions resources/views/admin/activities/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
@extends('admin.layouts.default')

@section('search')
<form class="navbar-form pull-left" role="search" action="{{ route('admin.activity.index') }}">
<div class="form-group">
<input type="hidden" name="type" value="activity">
<input type="text" name="q" class="form-control search-bar" placeholder="搜索" value="{{ Input::get('q') }}">
</div>
<button type="submit" class="btn btn-search"><i class="fa fa-search"></i></button>
</form>
@endsection

@section('mainBody')
<div class="">
<div class="page-header-title">
<h4 class="page-title">活动列表</h4>
</div>
</div>

<div class="page-content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="panel panel-primary">
<div class="panel-body">
<div class="row">
<div class="col-xs-12">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>#</th>
<th>活动缩略图</th>
<th>标题</th>
<th>TU TB F C R</th>
<th>发布时间</th>
<th>操作</th>
</tr>
</thead>
<tbody>
@if ($activities->isEmpty())
<tr>
<td colspan="5">无数据</td>
</tr>
@else
@foreach ($activities as $activity)
<tr>
<td>{{ $activity->id }}</td>
<td><img src="{{ $activity->avatar }}" alt="活动缩略图" style="width: 4rem;height: 4rem;border-radius: 50%;"></td>
<td><a target="_blank" href="{{ route('news.show', $activity->id) }}">{{ $activity->title }}</a></td>
<td>
{{ $activity->thumb_up_num }}
/
{{ $activity->thumb_down_num }}
/
{{ $activity->favorite_num }}
/
{{ $activity->comment_num }}
/
{{ $activity->read_num }}
</td>
<td>{{ $activity->created_at }}</td>
<td><a class="btn btn-xs btn-danger" onclick="activityDestroy('{{ $activity->title }}', {{ $activity->id }})" title="删除"><i class="fa fa-trash-o"></i></a></td>
</tr>
@endforeach
@endif
</tbody>
</table>

<!-- Pagination -->
<nav id="section-pagination">
{{ $activities->links() }}
</nav>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

<script>
function activityDestroy(title,id) {
var message = '是否要删除 ' + title + '这条活动';

if (confirm(message)) {
var url = '{{ route('admin.activity.destroy') }}';
postSubmit(url, {id: id});
}
}
</script>
</div>
@stop
31 changes: 24 additions & 7 deletions resources/views/admin/layouts/default.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@
</button>
<span class="clearfix"></span>
</div>
<form class="navbar-form pull-left" role="search">
<div class="form-group">
<input type="text" class="form-control search-bar" placeholder="搜索暂不可用" disabled>
</div>
<button type="submit" class="btn btn-search"><i class="fa fa-search"></i></button>
</form>
@yield('search')

<ul class="nav navbar-nav navbar-right pull-right">
<li class="dropdown hidden-xs">
Expand Down Expand Up @@ -146,6 +141,19 @@
</a>
</li>



<li class="has_sub">
<a href="javascript:void(0);" class="waves-effect">
<i class="mdi mdi-comment-text"></i>
<span>新闻管理</span>
<span class="pull-right"><i class="mdi mdi-plus"></i></span>
</a>
<ul class="list-unstyled">
<li><a href="{{ route('admin.news.index') }}">新闻列表</a></li>
</ul>
</li>

<li class="has_sub">
<a href="javascript:void(0);" class="waves-effect">
<i class="mdi mdi-comment-text"></i>
Expand All @@ -157,7 +165,16 @@
<li><a href="{{ route('admin.topic.node.index') }}">节点管理</a></li>
</ul>
</li>

<li class="has_sub">
<a href="javascript:void(0);" class="waves-effect">
<i class="mdi mdi-comment-text"></i>
<span>活动管理</span>
<span class="pull-right"><i class="mdi mdi-plus"></i></span>
</a>
<ul class="list-unstyled">
<li><a href="{{ route('admin.activity.index') }}">活动列表</a></li>
</ul>
</li>
<li>
<a href="{{ route('admin.system.edit') }}" class="waves-effect">
<i class="mdi mdi-wrench"></i>
Expand Down
Loading