Skip to content

Commit

Permalink
Subscribe to newsletter was added
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgefortzz committed May 20, 2017
1 parent 828a889 commit 39ec66a
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 34 deletions.
29 changes: 29 additions & 0 deletions app/Http/Controllers/SubscribeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Controllers;

use App\Subscribe;
use Illuminate\Http\Request;

class SubscribeController extends Controller
{
public function store(Request $request){

/*
* Validate e-mail correctness
*/
$this->validate($request, [
'email' => 'required|email|max:255|unique:subscribers'
]);

// Put new e-mail into a subscribe list

$subscribe = new Subscribe();
$subscribe->email = $request->email;
$subscribe->save();

session()->flash('subscribed', 'You subscribed to our newsletter');

return back();
}
}
10 changes: 10 additions & 0 deletions app/Subscribe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Subscribe extends Model
{
protected $table = 'subscribers';
}
32 changes: 32 additions & 0 deletions database/migrations/2017_05_20_202514_create_subscribers_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

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

class CreateSubscribersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('subscribers', function (Blueprint $table) {
$table->increments('id');
$table->string('email')->unique();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('subscribers');
}
}
33 changes: 33 additions & 0 deletions resources/views/layouts/footer.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,39 @@
<p><span class="glyphicon glyphicon-earphone"></span><b> Phone (Poland) : +48 000 000 000</b></p>
</div>
</div>

{{--Subscribe to newsletter--}}
<div class="col-md-3 col-sm-6 paddingtop-bottom">
<div class="text-center center-block">
<div class="row">
<div class="center well well-sm text-center">
<h2>Newsletter</h2>

<p>Subscribe to our weekly Newsletter and stay tuned.</p>

<form role="form" action="{{ url('/subscribe') }}" method="POST">
{{csrf_field()}}
<div class="input-group form-group">
<span class="input-group-addon">
<i class="fa fa-envelope"></i>
</span>
<input id="email" name="email" class="form-control" type="text" placeholder="your@email.com" required>
</div>

@if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
@endif

<div class="form-group">
<button type="submit" class="btn btn-default" style="margin-top: 10px">Subscribe</button>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</footer>
Expand Down
4 changes: 4 additions & 0 deletions resources/views/layouts/nav_bar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
<div class="alert alert-danger flash-message text-center">{{ Session::get('removed_account') }}</div>
@endif

@if(Session::has('subscribed'))
<div class="alert alert-success flash-message text-center">{{ Session::get('subscribed') }}</div>
@endif

{{--AJAX flash messages--}}
<div id="added_to_cart" class="alert alert-success flash-message" hidden>Added new product</div>
<div id="removed_from_cart" class="alert alert-danger flash-message" hidden>Removed product</div>
Expand Down
72 changes: 38 additions & 34 deletions resources/views/main_page.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,43 +67,47 @@
{{--Horizontal line--}}
<hr>

<!-- Recommended products slider-->
<div class="row" style="margin-top: 30px; margin-bottom: 30px">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="carousel carousel-showmanymoveone slide" id="itemslider">
<div class="carousel-inner">

@foreach($recommendedProducts as $recommendedProduct)
@if($recommendedProducts->first() == $recommendedProduct)
<div class="item active">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_image}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
</div>
@else
<div class="item">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_image}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
</div>
@endif
@endforeach
</div>

<div id="slider-control">
<a class="left carousel-control" href="#itemslider" data-slide="prev"><img src="https://s12.postimg.org/uj3ffq90d/arrow_left.png" alt="Left" class="img-responsive" aria-hidden="true"></a>
<a class="right carousel-control" href="#itemslider" data-slide="next"><img src="https://s12.postimg.org/djuh0gxst/arrow_right.png" alt="Right" class="img-responsive" aria-hidden="true"></a>
@if(count($recommendedProducts) > 0)
<div id="recommended_products_section">
<!-- Recommended products slider-->
<div class="row" style="margin-top: 30px; margin-bottom: 30px">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="carousel carousel-showmanymoveone slide" id="itemslider">
<div class="carousel-inner">

@foreach($recommendedProducts as $recommendedProduct)
@if($recommendedProducts->first() == $recommendedProduct)
<div class="item active">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_image}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
</div>
@else
<div class="item">
<div class="col-xs-12 col-sm-6 col-md-2">
<a href="{{ url('/products/'.$recommendedProduct->id) }}"><img src="{{$recommendedProduct->path_to_image}}" class="img-responsive center-block"></a>
<h4 class="text-center">{{$recommendedProduct->name}}</h4>
<h5 class="text-center" style="color: darkred">${{$recommendedProduct->price}}</h5>
</div>
</div>
@endif
@endforeach
</div>

<div id="slider-control">
<a class="left carousel-control" href="#itemslider" data-slide="prev"><img src="https://s12.postimg.org/uj3ffq90d/arrow_left.png" alt="Left" class="img-responsive" aria-hidden="true"></a>
<a class="right carousel-control" href="#itemslider" data-slide="next"><img src="https://s12.postimg.org/djuh0gxst/arrow_right.png" alt="Right" class="img-responsive" aria-hidden="true"></a>
</div>
</div>
</div>
</div>
</div>
</div>

{{--Horizontal line--}}
<hr>
{{--Horizontal line--}}
<hr>
</div>
@endif
</div>

{{-- AJAX scripts--}}
Expand Down
5 changes: 5 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,8 @@
Route::get('/termsAndConditions', function () {
return view('info.terms_and_conditions');
});

/**
* Newsletter subscribe
*/
Route::post('/subscribe', 'SubscribeController@store');

0 comments on commit 39ec66a

Please sign in to comment.