-
Notifications
You must be signed in to change notification settings - Fork 3
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
Showing
13 changed files
with
344 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,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!'); | ||
} | ||
} |
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,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']; | ||
} |
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
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 | ||
{ | ||
|
||
} |
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,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
34
database/migrations/2017_07_13_112605_create_settings_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,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'); | ||
} | ||
} |
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
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> |
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,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> |
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,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 |
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,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 |
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,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 |
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