-
Notifications
You must be signed in to change notification settings - Fork 49
Send Email Views
JP Barbosa edited this page Mar 11, 2016
·
3 revisions
nano app/Http/Controllers/RecommendationsController.php
...
class RecommendationsController extends Controller
{
public function create(Article $article)
{
return view('recommendations.create', compact('article'));
}
public function store(RecommendationRequest $request, Article $article, ArticleMailer $mailer)
{
$mailer->recommendTo($request->input('email'), $article);
session()->flash('flash_message', 'Your recommendation was sent.');
if (Request::wantsJson()) {
return ['Your recommendation was sent.'];
} else {
return redirect('articles');
}
}
}
mkdir resources/views/recommendations/
nano resources/views/recommendations/create.blade.php
@extends($layout)
@section('content')
@include('shared.alert')
<h4>Recommend "{{ $article->title }}" by e-mail</h4>
<p>
{!! Form::open(['route' => ['articles.recommendations.store', $article->id]]) !!}
<div class='form-group'>
{!! Form::label('email', 'Email:') !!}
{!! Form::text('email', null, ['class' => 'form-control']) !!}
</div>
{!! Form::submit('Send Recommendation', ['class' => 'btn btn-primary']) !!}
{!! Form::close() !!}
</p>
@endsection
nano resources/views/articles/index.blade.php
...
<table class="table">
<tr>
<th>Edit</th>
<th>Delete</th>
<th>Recommend</th>
<th>Title</th>
<th>Author</th>
</tr>
@foreach ($articles as $article)
<tr>
<td>{!! link_to_route('articles.edit', 'Edit', $article->id, ['class' => 'btn btn-default']) !!}</td>
<td>
{!! Form::open(['method' => 'DELETE', 'route' => ['articles.destroy', $article->id]]) !!}
<button type="submit" class="btn btn-warning">Delete</button>
{!! Form::close() !!}
</td>
<td>{!! link_to_route('articles.recommendations.create', 'Recommend', $article->id) !!}</td>
<td>{!! link_to_route('articles.show', $article->title, $article->id) !!}</td>
<td>{!! $article->author->name !!}</td>
</tr>
@endforeach
</table>
...
open http://localhost:8000/articles/1/recommendations/create
tail storage/logs/laravel.log
git add .
git commit -m "Add mailer views"
Next step: Jobs Queue
- Setup
- Basic CRUD
- Validation
- Views
- Association
- Association Controller
- Association Views
- Basic Template
- Bootstrap
- Bootstrap CRUD
- Alerts
- Welcome Page
- Ajax CRUD
- Send Email
- Send Email Views
- Jobs Queue
- Captcha
- Async External Content
- Cached External Content
- Tests Setup
- Functional Tests
- Acceptance Tests
- Continuous Integration
- Deploy with Heroku
- Deploy with Forge
- Update README