Skip to content

Commit

Permalink
Merge pull request #1 from Laralum/analysis-Xk73Mj
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
24aitor authored Apr 15, 2017
2 parents a9e7b8d + b4ec8f1 commit 84bc2dd
Show file tree
Hide file tree
Showing 19 changed files with 297 additions and 297 deletions.
13 changes: 7 additions & 6 deletions src/Controllers/NotificationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
namespace Laralum\Notifications\Controllers;

use App\Http\Controllers\Controller;
use Auth;
use Illuminate\Http\Request;
use Laralum\Notifications\Models\Notification;
use Laralum\Notifications\Models\Settings;
use Illuminate\Http\Request;
use Laralum\Users\Models\User;
use Laralum\Notifications\Notifications\MessageNotification;
use Auth;
use Laralum\Users\Models\User;

class NotificationsController extends Controller
{
Expand All @@ -32,6 +32,7 @@ public function show(Notification $notification)
$this->authorize('view', $notification);

$notification->markAsRead();

return view('laralum_notifications::show', ['notification' => $notification]);
}

Expand All @@ -50,15 +51,16 @@ public function create()
/**
* Store a newly created notification in storage.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->authorize('create', Notification::class);

$this->validate($request, [
'email' => 'required|email|exists:users,email',
'email' => 'required|email|exists:users,email',
'subject' => 'required|min:10|max:30',
'message' => 'required|max:1500',
]);
Expand All @@ -68,7 +70,6 @@ public function store(Request $request)
User::where(['email' => $request->email])->first()
->notify(new MessageNotification($request->subject, $request->message, $me));


return redirect()->route('laralum::notifications.index')->with('success', __('laralum_notifications::general.notification_sent'));
}

Expand Down
5 changes: 3 additions & 2 deletions src/DatabaseNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DatabaseNotification extends Model
* @var array
*/
protected $casts = [
'data' => 'array',
'data' => 'array',
'read_at' => 'datetime',
];

Expand Down Expand Up @@ -80,7 +80,8 @@ public function unread()
/**
* Create a new database notification collection instance.
*
* @param array $models
* @param array $models
*
* @return \Illuminate\Notifications\DatabaseNotificationCollection
*/
public function newCollection(array $models = [])
Expand Down
6 changes: 3 additions & 3 deletions src/Injectors/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

return [
[
'text' => __('laralum_notifications::general.my_notifications'),
'url' => route('laralum::notifications.index'),
'text' => __('laralum_notifications::general.my_notifications'),
'url' => route('laralum::notifications.index'),
'counter' => Laralum\Users\Models\User::findOrFail(Auth::id())->unreadNotifications->count(),
],
[
'text' => __('laralum_notifications::general.create_notification'),
'url' => route('laralum::notifications.create'),
]
],
];
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

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

class CreateLaralumNotifications extends Migration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Laralum\Notifications\Models\Settings;

class CreateLaralumNotificationsSettings extends Migration
Expand All @@ -21,7 +21,7 @@ public function up()
});

Settings::create([
'mail_enabled' => false
'mail_enabled' => false,
]);
}

Expand Down
1 change: 0 additions & 1 deletion src/Models/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ class Notification extends DatabaseNotification
* @var string
*/
protected $table = 'laralum_notifications';

}
3 changes: 1 addition & 2 deletions src/Models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ class Settings extends DatabaseNotification
* @var array
*/
protected $fillable = [
'mail_enabled'
'mail_enabled',
];

}
18 changes: 10 additions & 8 deletions src/Notifications/MessageNotification.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace Laralum\Notifications\Notifications;

use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Laralum\Notifications\Models\Settings;

class MessageNotification extends Notification
Expand All @@ -31,7 +30,8 @@ public function __construct($subject, $message, $user = null)
/**
* Get the notification's delivery channels.
*
* @param mixed $notifiable
* @param mixed $notifiable
*
* @return array
*/
public function via($notifiable)
Expand All @@ -42,12 +42,13 @@ public function via($notifiable)
/**
* Get the mail representation of the notification.
*
* @param mixed $notifiable
* @param mixed $notifiable
*
* @return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
return (new MailMessage())
->subject($this->subject)
->greeting(__('laralum_notifications::general.new_notification'))
->line(__('laralum_notifications::general.new_message'))
Expand All @@ -57,15 +58,16 @@ public function toMail($notifiable)
/**
* Get the database representation of the notification.
*
* @param mixed $notifiable
* @param mixed $notifiable
*
* @return array
*/
public function toDatabase ($notifiable)
public function toDatabase($notifiable)
{
return [
'subject' => $this->subject,
'message' => $this->message,
'user' => $this->user,
'user' => $this->user,
];
}
}
18 changes: 8 additions & 10 deletions src/NotificationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace Laralum\Notifications;

use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Gate;

use Illuminate\Support\ServiceProvider;
use Laralum\Notifications\Models\Notification;
use Laralum\Notifications\Policies\NotificationsPolicy;
use Laralum\Notifications\Models\Settings;
use Laralum\Notifications\Policies\NotificationsPolicy;
use Laralum\Notifications\Policies\SettingsPolicy;

use Laralum\Permissions\PermissionsChecker;

class NotificationsServiceProvider extends ServiceProvider
Expand All @@ -21,7 +19,7 @@ class NotificationsServiceProvider extends ServiceProvider
*/
protected $policies = [
Notification::class => NotificationsPolicy::class,
Settings::class => SettingsPolicy::class,
Settings::class => SettingsPolicy::class,
];

/**
Expand All @@ -33,23 +31,23 @@ class NotificationsServiceProvider extends ServiceProvider
[
'name' => 'Notifications Access',
'slug' => 'laralum::notifications.access',
'desc' => "Grants access to laralum/notifications module",
'desc' => 'Grants access to laralum/notifications module',
],
[
'name' => 'Create Notifications',
'slug' => 'laralum::notifications.create',
'desc' => "Allows creating notifications",
'desc' => 'Allows creating notifications',
],
[
'name' => 'View Notifications',
'slug' => 'laralum::notifications.view',
'desc' => "Allows viewing notifications",
'desc' => 'Allows viewing notifications',
],
[
'name' => 'Edit Notifications Settings',
'slug' => 'laralum::notifications.settings',
'desc' => 'Allows edititing the notification settings',
]
],
];

/**
Expand All @@ -75,7 +73,7 @@ public function boot()
}

/**
* I cheated this comes from the AuthServiceProvider extended by the App\Providers\AuthServiceProvider
* I cheated this comes from the AuthServiceProvider extended by the App\Providers\AuthServiceProvider.
*
* Register the application's policies.
*
Expand Down
14 changes: 8 additions & 6 deletions src/Policies/NotificationsPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Laralum\Notifications\Policies;

use Laralum\Users\Models\User;
use Laralum\Notifications\Models\Notification;
use Illuminate\Auth\Access\HandlesAuthorization;
use Laralum\Notifications\Models\Notification;
use Laralum\Users\Models\User;

class NotificationsPolicy
{
Expand All @@ -26,7 +26,8 @@ public function before($user, $ability)
/**
* Determine if the current user can access notifications module.
*
* @param mixed $user
* @param mixed $user
*
* @return bool
*/
public function access($user)
Expand All @@ -37,7 +38,8 @@ public function access($user)
/**
* Determine if the current user can view the notifications.
*
* @param mixed $user
* @param mixed $user
*
* @return bool
*/
public function view($user, Notification $notification)
Expand All @@ -58,12 +60,12 @@ public function view($user, Notification $notification)
/**
* Determine if the current user can create notifications.
*
* @param mixed $user
* @param mixed $user
*
* @return bool
*/
public function create($user)
{
return User::findOrFail($user->id)->hasPermission('laralum::notifications.create');
}

}
6 changes: 3 additions & 3 deletions src/Policies/SettingsPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Laralum\Notifications\Policies;

use Laralum\Users\Models\User;
use Illuminate\Auth\Access\HandlesAuthorization;
use Laralum\Users\Models\User;

class SettingsPolicy
{
Expand All @@ -25,12 +25,12 @@ public function before($user, $ability)
/**
* Determine if the current user can edit the notification settings.
*
* @param mixed $user
* @param mixed $user
*
* @return bool
*/
public function update($user)
{
return User::findOrFail($user->id)->hasPermission('laralum::notifications.settings');
}

}
6 changes: 3 additions & 3 deletions src/Routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
'web', 'laralum.base', 'laralum.auth',
'can:access,Laralum\Notifications\Models\Notification',
],
'prefix' => config('laralum.settings.base_url'),
'prefix' => config('laralum.settings.base_url'),
'namespace' => 'Laralum\Notifications\Controllers',
'as' => 'laralum::'
'as' => 'laralum::',
], function () {
Route::post('notifications/settings', 'NotificationsController@settings')->name('notifications.settings.update');
Route::resource('notifications', 'NotificationsController', ['only' => ['index', 'show', 'create', 'store']]);
});
});
2 changes: 0 additions & 2 deletions src/Traits/HasLaralumNotifications.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Laralum\Notifications\Traits;

use Illuminate\Notifications\HasDatabaseNotifications;
use Laralum\Notifications\DatabaseNotification;
use Laralum\Notifications\Models\Notification;

trait HasLaralumNotifications
Expand All @@ -18,5 +17,4 @@ public function notifications()
return $this->morphMany(Notification::class, 'notifiable')
->orderBy('created_at', 'desc');
}

}
Loading

0 comments on commit 84bc2dd

Please sign in to comment.