8 Laravel E-Commerce Application Development - Settings Section Part 2
8 Laravel E-Commerce Application Development - Settings Section Part 2
TABLE OF CONTENT
https://www.larashout.com/settings-section-part-2 1/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
09 Conclusion
https://www.larashout.com/settings-section-part-2 2/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
Settings Section
https://www.larashout.com/settings-section-part-2 3/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
Route::get('logout', 'Admin\LoginController@logout')->name('admin.logout');
Route::group(['middleware' => ['auth:admin']], function () {
Route::get('/', function () {
return view('admin.dashboard.index');
})->name('admin.dashboard');
});
});
Just after the dashboard route, we will add two more routes
for our settings section.
Route::get('/settings', 'Admin\SettingController@index')->name('admin.settings'
Route::post('/settings', 'Admin\SettingController@update')->name('admin.setting
https://www.larashout.com/settings-section-part-2 4/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request;
use App\Http\Controllers\BaseController;
https://www.larashout.com/settings-section-part-2 5/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
Now, we will add two new methods in this class called index()
/**
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function index()
{
$this->setPageTitle('Settings', 'Manage Settings');
return view('admin.settings.index');
}
In the index method, rstly we are setting the page title and
subtitle, then returning the settings index view.
Now add the second method like below and leave it as it is, we
will update this method later in this post.
/**
* @param Request $request
*/
public function update(Request $request)
{
https://www.larashout.com/settings-section-part-2 6/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
In this le, we have updated the href link using the route()
helper function for settings menu link. Also we have used the
https://www.larashout.com/settings-section-part-2 7/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
Now we will update the link of settings in the header le. Open
resources/views/admin/partials/header.blade.php le and update the setting’s
link with the below one.
<li>
<a class="dropdown-item" href="{{ route('admin.settings') }}"><i class="fa
</li>
Now if you run your application and try to access the settings
page using settings menu, you will receive a view not found
exception from Laravel. We will create this view shortly.
namespace App\Traits;
use Illuminate\Http\UploadedFile;
use Illuminate\Support\Facades\Storage;
/**
* Trait UploadAble
* @package App\Traits
*/
trait UploadAble
{
/**
* @param UploadedFile $file
* @param null $folder
* @param string $disk
* @param null $filename
* @return false|string
*/
public function uploadOne(UploadedFile $file, $folder = null, $disk = 'publ
{
$name = !is_null($filename) ? $filename : str_random(25);
return $file->storeAs(
$folder,
$name . "." . $file->getClientOriginalExtension(),
$disk
);
}
/**
* @param null $path
https://www.larashout.com/settings-section-part-2 9/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
Learn More
use UploadAble;
https://www.larashout.com/settings-section-part-2 10/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
@php
$errors = Session::get('error');
$messages = Session::get('success');
$info = Session::get('info');
$warnings = Session::get('warning');
@endphp
@if ($errors) @foreach($errors as $key => $value)
<div class="alert alert-danger alert-dismissible" role="alert">
<button class="close" type="button" data-dismiss="alert">×</button>
<strong>Error!</strong> {{ $value }}
</div>
@endforeach @endif
https://www.larashout.com/settings-section-part-2 11/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
In this view, we are getting the ash messages of all types from
the Laravel session and then showing the different type of
bootstrap alerts based on the ash message type.
@extends('admin.app')
@section('content')
<div class="app-title">
<div>
<h1><i class="fa fa-cogs"></i> {{ $pageTitle }}</h1>
</div>
</div>
@include('admin.partials.flash')
https://www.larashout.com/settings-section-part-2 12/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
https://www.larashout.com/settings-section-part-2 13/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
</div>
</div>
</div>
</div>
@endsection
If you will try to load /admin/settings URL, you will get some errors
which are perfectly ne as we haven’t created the different
partials for this view.
1. general.blade.php
2. logo.blade.php
3. footer_seo.blade.php
4. social_links.blade.php
5. analytics.blade.php
6. payments.blade.php
Now after creating above les load the /admin/settings URL and
you will have a view something like below.
https://www.larashout.com/settings-section-part-2 14/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
general.blade.php
Open your general.blade.php e and add the below code in this le.
<div class="tile">
<form action="{{ route('admin.settings.update') }}" method="POST" role="for
@csrf
<h3 class="tile-title">General Settings</h3>
<hr>
<div class="tile-body">
<div class="form-group">
<label class="control-label" for="site_name">Site Name</label>
<input
https://www.larashout.com/settings-section-part-2 15/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
class="form-control"
type="text"
placeholder="Enter site name"
id="site_name"
name="site_name"
value="{{ config('settings.site_name') }}"
/>
</div>
<div class="form-group">
<label class="control-label" for="site_title">Site Title</label
<input
class="form-control"
type="text"
placeholder="Enter site title"
id="site_title"
name="site_title"
value="{{ config('settings.site_title') }}"
/>
</div>
<div class="form-group">
<label class="control-label" for="default_email_address">Defaul
<input
class="form-control"
type="email"
placeholder="Enter store default email address"
id="default_email_address"
name="default_email_address"
value="{{ config('settings.default_email_address') }}"
/>
</div>
<div class="form-group">
<label class="control-label" for="currency_code">Currency Code<
https://www.larashout.com/settings-section-part-2 16/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
<input
class="form-control"
type="text"
placeholder="Enter store currency code"
id="currency_code"
name="currency_code"
value="{{ config('settings.currency_code') }}"
/>
</div>
<div class="form-group">
<label class="control-label" for="currency_symbol">Currency Sym
<input
class="form-control"
type="text"
placeholder="Enter store currency symbol"
id="currency_symbol"
name="currency_symbol"
value="{{ config('settings.currency_symbol') }}"
/>
</div>
</div>
<div class="tile-footer">
<div class="row d-print-none mt-2">
<div class="col-12 text-right">
<button class="btn btn-success" type="submit"><i class="fa
</div>
</div>
</div>
</form>
</div>
https://www.larashout.com/settings-section-part-2 17/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
logo.blade.php
<div class="tile">
<form action="{{ route('admin.settings.update') }}" method="POST" role="for
@csrf
https://www.larashout.com/settings-section-part-2 18/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
https://www.larashout.com/settings-section-part-2 19/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
</div>
</div>
<div class="tile-footer">
<div class="row d-print-none mt-2">
<div class="col-12 text-right">
<button class="btn btn-success" type="submit"><i class="fa
</div>
</div>
</div>
</form>
</div>
@push('scripts')
<script>
loadFile = function(event, id) {
var output = document.getElementById(id);
output.src = URL.createObjectURL(event.target.files[0]);
};
</script>
@endpush
In this view we have added two le input elds for site_logo and
site_favicon . We have also added some javaScript to change the
placeholder image of each input when a new le will be
uploaded.
https://www.larashout.com/settings-section-part-2 20/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
footer_seo.blade.php
<div class="tile">
<form action="{{ route('admin.settings.update') }}" method="POST" role="for
@csrf
<h3 class="tile-title">Footer & SEO</h3>
<hr>
<div class="tile-body">
<div class="form-group">
<label class="control-label" for="footer_copyright_text">Footer
<textarea
class="form-control"
rows="4"
placeholder="Enter footer copyright text"
https://www.larashout.com/settings-section-part-2 21/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
id="footer_copyright_text"
name="footer_copyright_text"
>{{ config('settings.footer_copyright_text') }}</textarea>
</div>
<div class="form-group">
<label class="control-label" for="seo_meta_title">SEO Meta Titl
<input
class="form-control"
type="text"
placeholder="Enter seo meta title for store"
id="seo_meta_title"
name="seo_meta_title"
value="{{ config('settings.seo_meta_title') }}"
/>
</div>
<div class="form-group">
<label class="control-label" for="seo_meta_description">SEO Met
<textarea
class="form-control"
rows="4"
placeholder="Enter seo meta description for store"
id="seo_meta_description"
name="seo_meta_description"
>{{ config('settings.seo_meta_description') }}</textarea>
</div>
</div>
<div class="tile-footer">
<div class="row d-print-none mt-2">
<div class="col-12 text-right">
<button class="btn btn-success" type="submit"><i class="fa
</div>
</div>
https://www.larashout.com/settings-section-part-2 22/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
</div>
</form>
</div>
footer_seo.blade.php
<div class="tile">
<form action="{{ route('admin.settings.update') }}" method="POST" role="for
@csrf
<h3 class="tile-title">Social Links</h3>
<hr>
<div class="tile-body">
https://www.larashout.com/settings-section-part-2 23/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
<div class="form-group">
<label class="control-label" for="social_facebook">Facebook Pro
<input
class="form-control"
type="text"
placeholder="Enter facebook profile link"
id="social_facebook"
name="social_facebook"
value="{{ config('settings.social_facebook') }}"
/>
</div>
<div class="form-group">
<label class="control-label" for="social_twitter">Twitter Profi
<input
class="form-control"
type="text"
placeholder="Enter twitter profile link"
id="social_twitter"
name="social_twitter"
value="{{ config('settings.social_twitter') }}"
/>
</div>
<div class="form-group">
<label class="control-label" for="social_instagram">Instagram P
<input
class="form-control"
type="text"
placeholder="Enter instagram profile link"
id="social_instagram"
name="social_instagram"
value="{{ config('settings.social_instagram') }}"
/>
https://www.larashout.com/settings-section-part-2 24/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
</div>
<div class="form-group">
<label class="control-label" for="social_linkedin">LinkedIn Pro
<input
class="form-control"
type="text"
placeholder="Enter linkedin profile link"
id="social_linkedin"
name="social_linkedin"
value="{{ config('settings.social_linkedin') }}"
/>
</div>
</div>
<div class="tile-footer">
<div class="row d-print-none mt-2">
<div class="col-12 text-right">
<button class="btn btn-success" type="submit"><i class="fa
</div>
</div>
</div>
</form>
</div>
Here is how our Social Links section of settings will look like.
https://www.larashout.com/settings-section-part-2 25/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
analytics.blade.php
<div class="tile">
<form action="{{ route('admin.settings.update') }}" method="POST" role="for
@csrf
<h3 class="tile-title">Analytics</h3>
<hr>
<div class="tile-body">
<div class="form-group">
<label class="control-label" for="google_analytics">Google Anal
<textarea
class="form-control"
rows="4"
placeholder="Enter google analytics code"
https://www.larashout.com/settings-section-part-2 26/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
id="google_analytics"
name="google_analytics"
>{!! Config::get('settings.google_analytics') !!}</textarea>
</div>
<div class="form-group">
<label class="control-label" for="facebook_pixels">Facebook Pix
<textarea
class="form-control"
rows="4"
placeholder="Enter facebook pixel code"
id="facebook_pixels"
name="facebook_pixels"
>{{ Config::get('settings.facebook_pixels') }}</textarea>
</div>
</div>
<div class="tile-footer">
<div class="row d-print-none mt-2">
<div class="col-12 text-right">
<button class="btn btn-success" type="submit"><i class="fa
</div>
</div>
</div>
</form>
</div>
https://www.larashout.com/settings-section-part-2 27/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
payments.blade.php
<div class="tile">
<form action="{{ route('admin.settings.update') }}" method="POST" role="for
@csrf
<h3 class="tile-title">Payment Settings</h3>
<hr>
<div class="tile-body">
<div class="form-group">
<label class="control-label" for="stripe_payment_method">Stripe
<select name="stripe_payment_method" id="stripe_payment_method"
<option value="1" {{ (config('settings.stripe_payment_metho
<option value="0" {{ (config('settings.stripe_payment_metho
</select>
https://www.larashout.com/settings-section-part-2 28/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
</div>
<div class="form-group">
<label class="control-label" for="stripe_key">Key</label>
<input
class="form-control"
type="text"
placeholder="Enter stripe key"
id="stripe_key"
name="stripe_key"
value="{{ config('settings.stripe_key') }}"
/>
</div>
<div class="form-group pb-2">
<label class="control-label" for="stripe_secret_key">Secret Key
<input
class="form-control"
type="text"
placeholder="Enter stripe secret key"
id="stripe_secret_key"
name="stripe_secret_key"
value="{{ config('settings.stripe_secret_key') }}"
/>
</div>
<hr>
<div class="form-group pt-2">
<label class="control-label" for="paypal_payment_method">PayPal
<select name="paypal_payment_method" id="paypal_payment_method"
<option value="1" {{ (config('settings.paypal_payment_metho
<option value="0" {{ (config('settings.paypal_payment_metho
</select>
</div>
<div class="form-group">
https://www.larashout.com/settings-section-part-2 29/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
https://www.larashout.com/settings-section-part-2 30/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
/**
* @param Request $request
* @return \Illuminate\Http\RedirectResponse
*/
public function update(Request $request)
{
if ($request->has('site_logo') && ($request->file('site_logo') instanceof U
https://www.larashout.com/settings-section-part-2 31/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
if (config('settings.site_logo') != null) {
$this->deleteOne(config('settings.site_logo'));
}
$logo = $this->uploadOne($request->file('site_logo'), 'img');
Setting::set('site_logo', $logo);
if (config('settings.site_favicon') != null) {
$this->deleteOne(config('settings.site_favicon'));
}
$favicon = $this->uploadOne($request->file('site_favicon'), 'img');
Setting::set('site_favicon', $favicon);
} else {
$keys = $request->except('_token');
https://www.larashout.com/settings-section-part-2 32/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
When logo is uploaded it will resturn the path of logo with it’s
le name generated randomly, we are setting the site_logo vlaue
in database using the Setting facade.
Conclusion
That’s it for now, in the next post we will start creating the
categories section for our e-commerce application.
Code Repository
https://www.larashout.com/settings-section-part-2 33/73
2/13/2020 Laravel E-Commerce Application Development – Settings Section Part 2
REPLY
nbn pk says:
REPLY
LaraShout says:
Thanks
https://www.larashout.com/settings-section-part-2 34/73