Skip to content

Commit

Permalink
Merge branch 'develop' into seo
Browse files Browse the repository at this point in the history
  • Loading branch information
MilesPong committed Jul 13, 2017
2 parents b618764 + 3e45917 commit f7d9a32
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 0 deletions.
127 changes: 127 additions & 0 deletions app/Http/Controllers/Backend/SettingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace App\Http\Controllers\Backend;

use App\Repositories\Contracts\SettingRepository;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Validation\Rule;

class SettingController extends Controller
{
/**
* @var SettingRepository
*/
protected $settingRepo;

/**
* SettingController constructor.
* @param SettingRepository $settingRepo
*/
public function __construct(SettingRepository $settingRepo)
{
$this->settingRepo = $settingRepo;
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$settings = $this->settingRepo->paginate();

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

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('admin.settings.create');
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'key' => 'required|unique:settings,key',
'value' => 'required',
'tag' => 'required',
]);

$this->settingRepo->create($request->all());

return redirect()->route('admin.settings.index')->withSuccess('Create setting successfully');
}

/**
* 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)
{
$setting = $this->settingRepo->find($id);

return view('admin.settings.edit', compact('setting'));
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$this->validate($request, [
'key' => [
'required',
Rule::unique('settings')->ignore($id)
],
'value' => 'required',
'tag' => 'required',
]);

$this->settingRepo->update($request->all(), $id);

return redirect()->route('admin.settings.index')->withSuccess('Update setting successfully');

}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$this->settingRepo->delete($id);

return redirect()->route('admin.settings.index')->withSuccess('Delete setting successfully!');
}
}
17 changes: 17 additions & 0 deletions app/Models/Setting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

/**
* Class Setting
* @package App\Models
*/
class Setting extends Model
{
/**
* @var array
*/
protected $fillable = ['key', 'value', 'tag'];
}
2 changes: 2 additions & 0 deletions app/Providers/RepositoryServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ public function register()
\App\Repositories\Eloquent\PostRepositoryEloquent::class);
$this->app->bind(\App\Repositories\Contracts\VisitorRepository::class,
\App\Repositories\Eloquent\VisitorRepositoryEloquent::class);
$this->app->bind(\App\Repositories\Contracts\SettingRepository::class,
\App\Repositories\Eloquent\SettingRepositoryEloquent::class);
}
}
12 changes: 12 additions & 0 deletions app/Repositories/Contracts/SettingRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Repositories\Contracts;

/**
* Interface SettingRepository
* @package App\Repositories\Contracts
*/
interface SettingRepository extends RepositoryInterface
{

}
21 changes: 21 additions & 0 deletions app/Repositories/Eloquent/SettingRepositoryEloquent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Repositories\Eloquent;

use App\Models\Setting;
use App\Repositories\Contracts\SettingRepository;

/**
* Class SettingRepositoryEloquent
* @package App\Repositories\Eloquent
*/
class SettingRepositoryEloquent extends BaseRepository implements SettingRepository
{
/**
* @return string
*/
public function model()
{
return Setting::class;
}
}
34 changes: 34 additions & 0 deletions database/migrations/2017_07_13_112605_create_settings_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->increments('id');
$table->string('key')->unique();
$table->text('value')->nullable();
$table->string('tag')->index();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('settings');
}
}
1 change: 1 addition & 0 deletions resources/views/admin/partials/sidebar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
<li class="{!! setActiveClass('categories') !!}"><a href="{{ route('admin.categories.index') }}"><i class="fa fa-sitemap"></i> <span>Categories</span></a></li>
<li class="{!! setActiveClass('tags') !!}"><a href="{{ route('admin.tags.index') }}"><i class="fa fa-tags"></i> <span>Tags</span></a></li>
<li class="{!! setActiveClass('posts') !!}"><a href="{{ route('admin.posts.index') }}"><i class="fa fa-list"></i> <span>Posts</span></a></li>
<li class="{!! setActiveClass('settings') !!}"><a href="{{ route('admin.settings.index') }}"><i class="fa fa-cog"></i> <span>Settings</span></a></li>
</ul>
<!-- /.sidebar-menu -->
</section>
Expand Down
23 changes: 23 additions & 0 deletions resources/views/admin/settings/_form.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{{ csrf_field() }}

<!-- text input -->
<div class="form-group">
<label>Key</label>
<input type="text" class="form-control" placeholder="Key" name="key" value="{{ old('key', $setting->key) }}">
</div>

<div class="form-group">
<label>Value</label>
<input type="text" class="form-control" placeholder="Value" name="value" value="{{ old('value', $setting->value) }}">
</div>

<div class="form-group">
<label>Tag</label>
<input type="text" class="form-control" placeholder="Tag" name="tag" value="{{ old('tag', $setting->tag) }}">
</div>

<div class="form-group">
<button class="btn btn-primary pull-right" type="submit">
{{ isset($setting->id) ? 'Save' : 'Submit' }}
</button>
</div>
33 changes: 33 additions & 0 deletions resources/views/admin/settings/_list.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<table id="example" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>ID</th>
<th>Key</th>
<th>Value</th>
<th>Tag</th>
<th>Action</th>
</tr>
</thead>
<tbody>
@foreach($settings as $setting)
<tr>
<td>{{ $setting->id }}</td>
<td>{{ $setting->key }}</td>
<td>{{ $setting->value }}</td>
<td>{{ $setting->tag }}</td>
<td>
<a class="btn btn-primary" href="{{ route('admin.settings.edit', $setting->id) }}">Edit</a>
<form action="{{ route('admin.settings.destroy', $setting->id) }}" method="POST" style="display: inline;">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button type='submit' class="btn btn-danger">Delete</button>
</form>
</td>
</tr>
@endforeach
</tbody>
</table>

<div class="pull-right">
{{ $settings->links() }}
</div>
28 changes: 28 additions & 0 deletions resources/views/admin/settings/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
@extends('admin.layouts.app')

@inject('setting', 'App\Models\Setting')

@section('content')
<div class="row">
<div class="col-md-12">

<!-- general form elements disabled -->
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">Setting Info</h3>
</div>
<!-- /.box-header -->
<div class="box-body">

<form role="form" action="{{ route('admin.settings.store') }}" method="POST">

@include('admin.settings._form')

</form>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>
@endsection
27 changes: 27 additions & 0 deletions resources/views/admin/settings/edit.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
@extends('admin.layouts.app')

@section('content')
<div class="row">
<div class="col-md-12">

<!-- general form elements disabled -->
<div class="box box-warning">
<div class="box-header with-border">
<h3 class="box-title">Setting Info</h3>
</div>
<!-- /.box-header -->
<div class="box-body">

<form role="form" action="{{ route('admin.settings.update', $setting->id) }}" method="POST">
{{ method_field('PATCH') }}

@include('admin.settings._form')

</form>
</div>
<!-- /.box-body -->
</div>
<!-- /.box -->
</div>
</div>
@endsection
17 changes: 17 additions & 0 deletions resources/views/admin/settings/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@extends('admin.layouts.app')

@section('content')
<a href="{{ route('admin.settings.create') }}" class="btn btn-lg btn-primary btn-flat" style="margin-bottom: 15px;">Add New</a>

<div class="row">
<div class="col-xs-12">

<div class="box box-default">
<div class="box-body">
@include('admin.settings._list')
</div>
</div>
</div>
</div>

@endsection
2 changes: 2 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
Route::resource('posts', 'PostController');

Route::post('auto-slug', 'DashboardController@autoSlug')->name('auto-slug');

Route::resource('settings', 'SettingController', ['except' => ['show']]);
});

Route::group(['namespace' => 'Frontend'], function () {
Expand Down

0 comments on commit f7d9a32

Please sign in to comment.