Skip to content

Commit 220f795

Browse files
committed
Settings added
1 parent 19a316c commit 220f795

File tree

14 files changed

+489
-2
lines changed

14 files changed

+489
-2
lines changed

composer.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
"autoload": {
2626
"psr-4": {
2727
"Appzcoder\\LaravelAdmin\\": "src/"
28-
}
28+
},
29+
"files": [
30+
"helpers.php"
31+
]
2932
},
3033
"extra": {
3134
"laravel": {
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Admin;
4+
5+
use App\Http\Requests;
6+
use App\Http\Controllers\Controller;
7+
8+
use App\Setting;
9+
use Illuminate\Http\Request;
10+
11+
class SettingsController extends Controller
12+
{
13+
/**
14+
* Display a listing of the resource.
15+
*
16+
* @return \Illuminate\View\View
17+
*/
18+
public function index(Request $request)
19+
{
20+
$keyword = $request->get('search');
21+
$perPage = 25;
22+
23+
if (!empty($keyword)) {
24+
$settings = Setting::where('key', 'LIKE', "%$keyword%")
25+
->orWhere('value', 'LIKE', "%$keyword%")
26+
->orderBy('key')->paginate($perPage);
27+
} else {
28+
$settings = Setting::orderBy('key')->paginate($perPage);
29+
}
30+
31+
return view('admin.settings.index', compact('settings'));
32+
}
33+
34+
/**
35+
* Show the form for creating a new resource.
36+
*
37+
* @return \Illuminate\View\View
38+
*/
39+
public function create()
40+
{
41+
return view('admin.settings.create');
42+
}
43+
44+
/**
45+
* Store a newly created resource in storage.
46+
*
47+
* @param \Illuminate\Http\Request $request
48+
*
49+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
50+
*/
51+
public function store(Request $request)
52+
{
53+
$this->validate(
54+
$request,
55+
[
56+
'key' => 'required|string|unique:settings',
57+
'value' => 'required'
58+
]
59+
);
60+
61+
$requestData = $request->all();
62+
63+
Setting::create($requestData);
64+
65+
return redirect('admin/settings')->with('flash_message', 'Setting added!');
66+
}
67+
68+
/**
69+
* Display the specified resource.
70+
*
71+
* @param int $id
72+
*
73+
* @return \Illuminate\View\View
74+
*/
75+
public function show($id)
76+
{
77+
$setting = Setting::findOrFail($id);
78+
79+
return view('admin.settings.show', compact('setting'));
80+
}
81+
82+
/**
83+
* Show the form for editing the specified resource.
84+
*
85+
* @param int $id
86+
*
87+
* @return \Illuminate\View\View
88+
*/
89+
public function edit($id)
90+
{
91+
$setting = Setting::findOrFail($id);
92+
93+
return view('admin.settings.edit', compact('setting'));
94+
}
95+
96+
/**
97+
* Update the specified resource in storage.
98+
*
99+
* @param \Illuminate\Http\Request $request
100+
* @param int $id
101+
*
102+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
103+
*/
104+
public function update(Request $request, $id)
105+
{
106+
$this->validate(
107+
$request,
108+
[
109+
'key' => 'required|string|unique:settings,key,' . $id,
110+
'value' => 'required'
111+
]
112+
);
113+
$requestData = $request->all();
114+
115+
$setting = Setting::findOrFail($id);
116+
$setting->update($requestData);
117+
118+
return redirect('admin/settings')->with('flash_message', 'Setting updated!');
119+
}
120+
121+
/**
122+
* Remove the specified resource from storage.
123+
*
124+
* @param int $id
125+
*
126+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
127+
*/
128+
public function destroy($id)
129+
{
130+
Setting::destroy($id);
131+
132+
return redirect('admin/settings')->with('flash_message', 'Setting deleted!');
133+
}
134+
}

publish/Model/Setting.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace App;
4+
5+
use Illuminate\Database\Eloquent\Model;
6+
use Spatie\Activitylog\Traits\LogsActivity;
7+
8+
class Setting extends Model
9+
{
10+
use LogsActivity;
11+
12+
13+
/**
14+
* The database table used by the model.
15+
*
16+
* @var string
17+
*/
18+
protected $table = 'settings';
19+
20+
/**
21+
* The database primary key value.
22+
*
23+
* @var string
24+
*/
25+
protected $primaryKey = 'id';
26+
27+
/**
28+
* Attributes that should be mass-assignable.
29+
*
30+
* @var array
31+
*/
32+
protected $fillable = ['key', 'value'];
33+
34+
35+
36+
/**
37+
* Change activity log event description
38+
*
39+
* @param string $eventName
40+
*
41+
* @return string
42+
*/
43+
public function getDescriptionForEvent($eventName)
44+
{
45+
return __CLASS__ . " model has been {$eventName}";
46+
}
47+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
6+
class CreateSettingsTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::create('settings', function (Blueprint $table) {
16+
$table->increments('id');
17+
$table->string('key')->unique();
18+
$table->string('value')->nullable();
19+
});
20+
}
21+
22+
/**
23+
* Reverse the migrations.
24+
*
25+
* @return void
26+
*/
27+
public function down()
28+
{
29+
Schema::drop('settings');
30+
}
31+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"menus":[{"section":"Resources","items":[{"title":"Users","url":"\/admin\/users"},{"title":"Roles","url":"\/admin\/roles"},{"title":"Permissions","url":"\/admin\/permissions"},{"title":"Pages","url":"\/admin\/pages"},{"title":"Activity Logs","url":"\/admin\/activitylogs"}]},{"section":"Tools","items":[{"title":"Generator","url":"\/admin\/generator"}]}]}
1+
{"menus":[{"section":"Resources","items":[{"title":"Users","url":"\/admin\/users"},{"title":"Roles","url":"\/admin\/roles"},{"title":"Permissions","url":"\/admin\/permissions"},{"title":"Pages","url":"\/admin\/pages"},{"title":"Activity Logs","url":"\/admin\/activitylogs"},{"title":"Settings","url":"\/admin\/settings"}]},{"section":"Tools","items":[{"title":"Generator","url":"\/admin\/generator"}]}]}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@extends('layouts.backend')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row">
6+
@include('admin.sidebar')
7+
8+
<div class="col-md-9">
9+
<div class="card">
10+
<div class="card-header">Create New Setting</div>
11+
<div class="card-body">
12+
<a href="{{ url('/admin/settings') }}" title="Back"><button class="btn btn-warning btn-sm"><i class="fa fa-arrow-left" aria-hidden="true"></i> Back</button></a>
13+
<br />
14+
<br />
15+
16+
@if ($errors->any())
17+
<ul class="alert alert-danger">
18+
@foreach ($errors->all() as $error)
19+
<li>{{ $error }}</li>
20+
@endforeach
21+
</ul>
22+
@endif
23+
24+
{!! Form::open(['url' => '/admin/settings', 'class' => 'form-horizontal', 'files' => true]) !!}
25+
26+
@include ('admin.settings.form', ['formMode' => 'create'])
27+
28+
{!! Form::close() !!}
29+
30+
</div>
31+
</div>
32+
</div>
33+
</div>
34+
</div>
35+
@endsection
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
@extends('layouts.backend')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row">
6+
@include('admin.sidebar')
7+
8+
<div class="col-md-9">
9+
<div class="card">
10+
<div class="card-header">Edit Setting #{{ $setting->id }}</div>
11+
<div class="card-body">
12+
<a href="{{ url('/admin/settings') }}" title="Back"><button class="btn btn-warning btn-sm"><i class="fa fa-arrow-left" aria-hidden="true"></i> Back</button></a>
13+
<br />
14+
<br />
15+
16+
@if ($errors->any())
17+
<ul class="alert alert-danger">
18+
@foreach ($errors->all() as $error)
19+
<li>{{ $error }}</li>
20+
@endforeach
21+
</ul>
22+
@endif
23+
24+
{!! Form::model($setting, [
25+
'method' => 'PATCH',
26+
'url' => ['/admin/settings', $setting->id],
27+
'class' => 'form-horizontal',
28+
'files' => true
29+
]) !!}
30+
31+
@include ('admin.settings.form', ['formMode' => 'edit'])
32+
33+
{!! Form::close() !!}
34+
35+
</div>
36+
</div>
37+
</div>
38+
</div>
39+
</div>
40+
@endsection
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<div class="form-group{{ $errors->has('key') ? 'has-error' : ''}}">
2+
{!! Form::label('key', 'Key', ['class' => 'control-label']) !!}
3+
{!! Form::text('key', null, ('required' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control']) !!}
4+
{!! $errors->first('key', '<p class="help-block">:message</p>') !!}
5+
</div>
6+
<div class="form-group{{ $errors->has('value') ? 'has-error' : ''}}">
7+
{!! Form::label('value', 'Value', ['class' => 'control-label']) !!}
8+
{!! Form::text('value', null, ('required' == 'required') ? ['class' => 'form-control', 'required' => 'required'] : ['class' => 'form-control']) !!}
9+
{!! $errors->first('value', '<p class="help-block">:message</p>') !!}
10+
</div>
11+
12+
<div class="form-group">
13+
{!! Form::submit($formMode === 'edit' ? 'Update' : 'Create', ['class' => 'btn btn-primary']) !!}
14+
</div>
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
@extends('layouts.backend')
2+
3+
@section('content')
4+
<div class="container">
5+
<div class="row">
6+
@include('admin.sidebar')
7+
8+
<div class="col-md-9">
9+
<div class="card">
10+
<div class="card-header">Settings</div>
11+
<div class="card-body">
12+
<a href="{{ url('/admin/settings/create') }}" class="btn btn-success btn-sm" title="Add New Setting">
13+
<i class="fa fa-plus" aria-hidden="true"></i> Add New
14+
</a>
15+
16+
{!! Form::open(['method' => 'GET', 'url' => '/admin/settings', 'class' => 'form-inline my-2 my-lg-0 float-right', 'role' => 'search']) !!}
17+
<div class="input-group">
18+
<input type="text" class="form-control" name="search" placeholder="Search..." value="{{ request('search') }}">
19+
<span class="input-group-append">
20+
<button class="btn btn-secondary" type="submit">
21+
<i class="fa fa-search"></i>
22+
</button>
23+
</span>
24+
</div>
25+
{!! Form::close() !!}
26+
27+
<br/>
28+
<br/>
29+
<div class="table-responsive">
30+
<table class="table table-borderless">
31+
<thead>
32+
<tr>
33+
<th>Key</th><th>Value</th><th>Usage</th><th>Actions</th>
34+
</tr>
35+
</thead>
36+
<tbody>
37+
@foreach($settings as $item)
38+
<tr>
39+
<td>{{ $item->key }}</td>
40+
<td>{{ $item->value }}</td>
41+
<td><code>setting('{{ $item->key }}')</code></td>
42+
<td>
43+
<a href="{{ url('/admin/settings/' . $item->id) }}" title="View Setting"><button class="btn btn-info btn-sm"><i class="fa fa-eye" aria-hidden="true"></i></button></a>
44+
<a href="{{ url('/admin/settings/' . $item->id . '/edit') }}" title="Edit Setting"><button class="btn btn-primary btn-sm"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></button></a>
45+
{!! Form::open([
46+
'method' => 'DELETE',
47+
'url' => ['/admin/settings', $item->id],
48+
'style' => 'display:inline'
49+
]) !!}
50+
{!! Form::button('<i class="fa fa-trash-o" aria-hidden="true"></i>', array(
51+
'type' => 'submit',
52+
'class' => 'btn btn-danger btn-sm',
53+
'title' => 'Delete Setting',
54+
'onclick'=>'return confirm("Confirm delete?")'
55+
)) !!}
56+
{!! Form::close() !!}
57+
</td>
58+
</tr>
59+
@endforeach
60+
</tbody>
61+
</table>
62+
<div class="pagination-wrapper"> {!! $settings->appends(['search' => Request::get('search')])->render() !!} </div>
63+
</div>
64+
65+
</div>
66+
</div>
67+
</div>
68+
</div>
69+
</div>
70+
@endsection

0 commit comments

Comments
 (0)