Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit 7915ae6

Browse files
author
Mario Basic
committed
Added settings with preferred currency and email notifications.
1 parent c6b9a2b commit 7915ae6

File tree

7 files changed

+257
-82
lines changed

7 files changed

+257
-82
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
use App\Http\Requests;
8+
9+
class SettingsController extends Controller
10+
{
11+
/**
12+
* Show the form for editing the specified resource.
13+
*
14+
* @return \Illuminate\Http\Response
15+
*/
16+
public function edit()
17+
{
18+
$user = auth()->user();
19+
$currencies = [
20+
'hrk' => 'HRK',
21+
'usd' => 'USD',
22+
'eur' => 'EUR'
23+
];
24+
25+
return view('settings.edit')->with(compact('user', 'currencies'));
26+
}
27+
28+
/**
29+
* Update the specified resource in storage.
30+
*
31+
* @param \Illuminate\Http\Request $request
32+
* @return \Illuminate\Http\Response
33+
*/
34+
public function update(Request $request)
35+
{
36+
$this->validate($request, [
37+
'name' => 'required|max:255',
38+
'email' => 'required|email|max:255|unique:users,email,' . auth()->user()->id,
39+
'password' => 'min:6|confirmed',
40+
'preferred_currency' => 'required|in:hrk,usd,eur',
41+
'email_notifications' => 'boolean'
42+
]);
43+
44+
auth()->user()->update([
45+
'name' => $request->get('name'),
46+
'email' => $request->get('email'),
47+
'preferred_currency' => $request->get('preferred_currency'),
48+
'email_notifications' => $request->get('email_notifications', false)
49+
]);
50+
51+
if($request->get('password', "") != "") {
52+
auth()->user()->password = bcrypt($request->get('password'));
53+
auth()->user()->save();
54+
}
55+
56+
flash()->success('Settings updated!');
57+
58+
return redirect('/settings');
59+
}
60+
61+
/**
62+
* Remove the specified resource from storage.
63+
*
64+
* @param int $id
65+
* @return \Illuminate\Http\Response
66+
*/
67+
public function destroy($id)
68+
{
69+
//
70+
}
71+
}

app/Http/routes.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
Route::group(['middleware' => 'auth'], function () {
1515
Route::get('/', 'HomeController@index');
1616

17+
Route::get('settings', 'SettingsController@edit');
18+
Route::put('settings', 'SettingsController@update');
19+
1720
Route::get('report', 'HomeController@report');
1821

1922
Route::resource('clients', 'ClientController');

app/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class User extends Authenticatable
1212
* @var array
1313
*/
1414
protected $fillable = [
15-
'name', 'email', 'password', 'api_token'
15+
'name', 'email', 'password', 'api_token', 'email_notifications', 'preferred_currency'
1616
];
1717

1818
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use Illuminate\Database\Schema\Blueprint;
4+
use Illuminate\Database\Migrations\Migration;
5+
6+
class AddPreferredCurrencyAndEmailNotificationsToUsersTable extends Migration
7+
{
8+
/**
9+
* Run the migrations.
10+
*
11+
* @return void
12+
*/
13+
public function up()
14+
{
15+
Schema::table('users', function (Blueprint $table) {
16+
$table->string('preferred_currency')->default('usd');
17+
$table->boolean('email_notifications')->default(true);
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('users', function (Blueprint $table) {
29+
$table->dropColumn('preferred_currency');
30+
$table->dropColumn('email_notifications');
31+
});
32+
}
33+
}

resources/views/layouts/app.blade.php

Lines changed: 1 addition & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -11,87 +11,7 @@
1111

1212
</head>
1313
<body id="app-layout">
14-
<nav class="navbar navbar-default navbar-static-top">
15-
<div class="container">
16-
<div class="navbar-header">
17-
18-
<!-- Collapsed Hamburger -->
19-
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
20-
<span class="sr-only">Toggle Navigation</span>
21-
<span class="icon-bar"></span>
22-
<span class="icon-bar"></span>
23-
<span class="icon-bar"></span>
24-
</button>
25-
26-
<!-- Branding Image -->
27-
<a class="navbar-brand" href="{{ url('/') }}">
28-
Kyle
29-
</a>
30-
</div>
31-
32-
<div class="collapse navbar-collapse" id="app-navbar-collapse">
33-
<!-- Left Side Of Navbar -->
34-
<ul class="nav navbar-nav">
35-
<li class="{{ Ekko::isActiveUrl('/') }}">
36-
<a href="{{ url('/') }}">
37-
<i class="fa fa-fw fa-bullseye"></i> Overview
38-
</a>
39-
</li>
40-
@if(Auth::check())
41-
<li class="dropdown {{ Ekko::areActiveRoutes(['services.*', 'categories.*']) }}">
42-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
43-
<i class="fa fa-fw fa-ship"></i> Services <span class="caret"></span>
44-
</a>
45-
46-
<ul class="dropdown-menu" role="menu">
47-
<li class="{{ Ekko::isActiveRoute('services.index') }}">
48-
<a href="{{ route('services.index') }}">
49-
Index
50-
</a>
51-
</li>
52-
<li class="{{ Ekko::isActiveRoute('categories.*') }}">
53-
<a href="{{ route('categories.index') }}">
54-
Categories
55-
</a>
56-
</li>
57-
</ul>
58-
</li>
59-
<li class="{{ Ekko::isActiveRoute('clients.*') }}">
60-
<a href="{{ route('clients.index') }}">
61-
<i class="fa fa-fw fa-users"></i> Clients
62-
</a>
63-
</li>
64-
@endif
65-
</ul>
66-
67-
<!-- Right Side Of Navbar -->
68-
<ul class="nav navbar-nav navbar-right">
69-
<!-- Authentication Links -->
70-
@if (Auth::guest())
71-
<li class="{{ Ekko::isActiveUrl('/login') }}">
72-
<a href="{{ url('/login') }}">Login</a>
73-
</li>
74-
{{-- <li><a href="{{ url('/register') }}">Register</a></li> --}}
75-
@else
76-
<li class="{{ Ekko::isActiveUrl('/report') }}">
77-
<a href="{{ url('/report') }}">
78-
<i class="fa fa-fw fa-line-chart"></i> Report
79-
</a>
80-
</li>
81-
<li class="dropdown">
82-
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
83-
{{ Auth::user()->name }} <span class="caret"></span>
84-
</a>
85-
86-
<ul class="dropdown-menu" role="menu">
87-
<li><a href="{{ url('/logout') }}"><i class="fa fa-btn fa-sign-out"></i> Logout</a></li>
88-
</ul>
89-
</li>
90-
@endif
91-
</ul>
92-
</div>
93-
</div>
94-
</nav>
14+
@include('layouts.partials.navbar')
9515

9616
@include('flash::message')
9717

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<nav class="navbar navbar-default navbar-static-top">
2+
<div class="container">
3+
<div class="navbar-header">
4+
5+
<!-- Collapsed Hamburger -->
6+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#app-navbar-collapse">
7+
<span class="sr-only">Toggle Navigation</span>
8+
<span class="icon-bar"></span>
9+
<span class="icon-bar"></span>
10+
<span class="icon-bar"></span>
11+
</button>
12+
13+
<!-- Branding Image -->
14+
<a class="navbar-brand" href="{{ url('/') }}">
15+
Kyle
16+
</a>
17+
</div>
18+
19+
<div class="collapse navbar-collapse" id="app-navbar-collapse">
20+
<!-- Left Side Of Navbar -->
21+
<ul class="nav navbar-nav">
22+
<li class="{{ Ekko::isActiveUrl('/') }}">
23+
<a href="{{ url('/') }}">
24+
<i class="fa fa-fw fa-bullseye"></i> Overview
25+
</a>
26+
</li>
27+
@if(Auth::check())
28+
<li class="dropdown {{ Ekko::areActiveRoutes(['services.*', 'categories.*']) }}">
29+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
30+
<i class="fa fa-fw fa-ship"></i> Services <span class="caret"></span>
31+
</a>
32+
33+
<ul class="dropdown-menu" role="menu">
34+
<li class="{{ Ekko::isActiveRoute('services.index') }}">
35+
<a href="{{ route('services.index') }}">
36+
Index
37+
</a>
38+
</li>
39+
<li class="{{ Ekko::isActiveRoute('categories.*') }}">
40+
<a href="{{ route('categories.index') }}">
41+
Categories
42+
</a>
43+
</li>
44+
</ul>
45+
</li>
46+
<li class="{{ Ekko::isActiveRoute('clients.*') }}">
47+
<a href="{{ route('clients.index') }}">
48+
<i class="fa fa-fw fa-users"></i> Clients
49+
</a>
50+
</li>
51+
@endif
52+
</ul>
53+
54+
<!-- Right Side Of Navbar -->
55+
<ul class="nav navbar-nav navbar-right">
56+
<!-- Authentication Links -->
57+
@if (Auth::guest())
58+
<li class="{{ Ekko::isActiveUrl('/login') }}">
59+
<a href="{{ url('/login') }}">Login</a>
60+
</li>
61+
{{-- <li><a href="{{ url('/register') }}">Register</a></li> --}}
62+
@else
63+
<li class="{{ Ekko::isActiveUrl('/report') }}">
64+
<a href="{{ url('/report') }}">
65+
<i class="fa fa-fw fa-line-chart"></i> Report
66+
</a>
67+
</li>
68+
<li class="dropdown {{ Ekko::isActiveUrl('/settings') }}">
69+
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
70+
{{ Auth::user()->name }} <span class="caret"></span>
71+
</a>
72+
73+
<ul class="dropdown-menu" role="menu">
74+
<li class="{{ Ekko::isActiveUrl('/settings') }}">
75+
<a href="{{ url('/settings') }}">
76+
<i class="fa fa-fw fa-cogs"></i> Settings
77+
</a>
78+
</li>
79+
<li class="divider"></li>
80+
<li><a href="{{ url('/logout') }}"><i class="fa fa-fw fa-sign-out"></i> Logout</a></li>
81+
</ul>
82+
</li>
83+
@endif
84+
</ul>
85+
</div>
86+
</div>
87+
</nav>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
@extends('layouts.app')
2+
3+
@section('meta_title', 'Settings')
4+
5+
@section('content')
6+
<div class="container">
7+
<div class="row">
8+
<div class="col-md-12">
9+
@include('layouts.partials.page_header', [
10+
'header' => 'Settings',
11+
'subtext' => 'Edit your settings here'
12+
])
13+
</div>
14+
</div>
15+
<div class="row">
16+
<div class="col-md-12">
17+
@include('layouts.partials.validation')
18+
19+
{{ Form::model($user, ['url' => '/settings', 'method' => 'PUT']) }}
20+
21+
<div class="form-group">
22+
{{ Form::label('name', 'Name') }}
23+
{{ Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Name']) }}
24+
</div>
25+
26+
<div class="form-group">
27+
{{ Form::label('email', 'Email') }}
28+
{{ Form::email('email', null, ['class' => 'form-control', 'placeholder' => 'Email']) }}
29+
</div>
30+
31+
<div class="form-group">
32+
{{ Form::label('password', 'Password') }}
33+
{{ Form::password('password', ['class' => 'form-control', 'placeholder' => 'Password']) }}
34+
</div>
35+
36+
<div class="form-group">
37+
{{ Form::label('password_confirmation', 'Password confirmation') }}
38+
{{ Form::password('password_confirmation', ['class' => 'form-control', 'placeholder' => 'Password confirmation']) }}
39+
</div>
40+
41+
<div class="form-group">
42+
{{ Form::label('preferred_currency', 'Preferred currency') }}
43+
{{ Form::select('preferred_currency', $currencies, null, [
44+
'class' => 'form-control',
45+
'placeholder' => 'Select a preferred currency'
46+
]) }}
47+
</div>
48+
49+
<div class="checkbox">
50+
<label>
51+
{{ Form::checkbox('email_notifications', '1') }} Receive email notifications?
52+
</label>
53+
</div>
54+
55+
<button type="submit" class="btn btn-primary">Update</button>
56+
57+
{{ Form::close() }}
58+
</div>
59+
</div>
60+
</div>
61+
@endsection

0 commit comments

Comments
 (0)