Skip to content

Commit

Permalink
Email log
Browse files Browse the repository at this point in the history
  • Loading branch information
JaviGR7 committed Apr 27, 2020
1 parent d3b5024 commit df9dcda
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/Http/Controllers/Follow/FollowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
namespace App\Http\Controllers\Follow;

use App\Http\Controllers\ApiController;
use App\Mail\NotifyFollowers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Mail;

class FollowController extends ApiController
{
Expand All @@ -15,6 +17,15 @@ public function index($user_id)
return response()->json($followers);
}

public function email($user_id){
$followers = DB::table('follows')->where('user_id', $user_id)->pluck('follower_id')->toArray();
$emails = DB::table('clients')->whereIn('id', $followers)->pluck('email');
$artista = DB::table('clients')->where('id', $user_id) ->pluck('username');
foreach($emails as $email){
Mail::to($email)->send(new NotifyFollowers($artista[0]));
}
}



/**
Expand Down
36 changes: 36 additions & 0 deletions app/Mail/NotifyFollowers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Mail;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;

class NotifyFollowers extends Mailable
{
use Queueable, SerializesModels;

public $subject = 'Nueva canción';

public $artista;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct($artista)
{
$this->artista = $artista;
}

/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('emails.notify-followers');
}
}
11 changes: 11 additions & 0 deletions resources/views/emails/notify-followers.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>Notificar Followers</title>
</head>
<body>
<p>El usuario {{$artista}} ha subido una nueva canción, ve a verla ya!</p>
<h3>Hola</h3>
</body>
</html>
1 change: 1 addition & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@
Route::get('/sheets/getuserlike/{sheets_id}/{clients_id}','LikedSong\LikedSongController@getuser')->name('likedsong.getuser');

Route::get('follows/{user_id}', 'Follow\FollowController@index')->name('follow.index');
Route::get('follows/notify/{user_id}', 'Follow\FollowController@email')->name('follow.email');
Route::post('follows', 'Follow\FollowController@store')->name('follow.store');
Route::delete('follows/{user_id}/{follower_id}', 'Follow\FollowController@destroy')->name('follow.destroy');

0 comments on commit df9dcda

Please sign in to comment.