WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit e03b37c

Browse files
committed
Merge branch 'develop', Laravel 5 updates
Conflicts: readme.md
2 parents 46a7177 + e95de14 commit e03b37c

File tree

15 files changed

+221
-122
lines changed

15 files changed

+221
-122
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
],
1212
"require": {
1313
"php": ">=5.4.0",
14-
"illuminate/support": "~4.0",
15-
"illuminate/database": "~4.0",
14+
"illuminate/support": "~5.0",
15+
"illuminate/database": "~5.0",
1616
"nesbot/carbon": "~1.0"
1717
},
1818
"require-dev": {

readme.md

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[![Build Status](https://img.shields.io/travis/cmgmyr/laravel-messenger.svg?style=flat-square)](https://travis-ci.org/cmgmyr/laravel-messenger)
22
[![Code Climate](https://img.shields.io/codeclimate/github/cmgmyr/laravel-messenger.svg?style=flat-square)](https://codeclimate.com/github/cmgmyr/laravel-messenger)
33
[![Latest Version](https://img.shields.io/github/release/cmgmyr/laravel-messenger.svg?style=flat-square)](https://github.com/cmgmyr/laravel-messenger/releases)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/cmgmyr/messenger.svg?style=flat-square)](https://packagist.org/packages/cmgmyr/messenger)
45
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
56

67
# Laravel Messenger
@@ -19,5 +20,63 @@ This package will allow you to add a full user messaging system into your Larave
1920
* Group messaging (only participants can see their threads)
2021
* One to one messaging (private or direct thread)
2122

22-
## Installation
23-
[Laravel 4](https://github.com/cmgmyr/laravel-messenger/tree/v1) | [Laravel 5](https://github.com/cmgmyr/laravel-messenger/tree/develop)
23+
## Installation (Laravel 4.x)
24+
Installation instruction for Laravel 4 can be [found here](https://github.com/cmgmyr/laravel-messenger/tree/v1).
25+
26+
## Installation (Laravel 5.x)
27+
In composer.json:
28+
29+
"require": {
30+
"cmgmyr/messenger": "~2.0"
31+
}
32+
33+
Run:
34+
35+
composer update
36+
37+
Add the service provider to `config/app.php` under `providers`:
38+
39+
'providers' => [
40+
'Cmgmyr\Messenger\MessengerServiceProvider'
41+
]
42+
43+
Publish Assets
44+
45+
php artisan vendor:publish --provider="Cmgmyr\Messenger\MessengerServiceProvider"
46+
47+
Update config file to reference your User Model:
48+
49+
config/messenger.php
50+
51+
Create a `users` table if you do not have one already. If you need one, simply use [this example](https://github.com/cmgmyr/laravel-messenger/tree/master/src/Cmgmyr/Messenger/examples/create_users_table.php) as a starting point, then migrate.
52+
53+
__Note:__ if you already have a `users` table and run into any issues with foreign keys, you may have to make the `id` unsigned.
54+
55+
Migrate your database:
56+
57+
php artisan migrate
58+
59+
Add the trait to your user model:
60+
61+
use Cmgmyr\Messenger\Traits\Messagable;
62+
63+
class User extends Model {
64+
use Messagable;
65+
}
66+
67+
68+
## Examples
69+
* [Controller](https://github.com/cmgmyr/laravel-messenger/tree/master/src/Cmgmyr/Messenger/examples/MessagesController.php)
70+
* [Routes](https://github.com/cmgmyr/laravel-messenger/tree/master/src/Cmgmyr/Messenger/examples/routes.php)
71+
* [Views](https://github.com/cmgmyr/laravel-messenger/tree/master/src/Cmgmyr/Messenger/examples/views)
72+
73+
__Note:__ These examples use the [illuminate/html](https://packagist.org/packages/illuminate/html) package that is no longer included in Laravel 5 out of the box. Make sure you require this dependency in your `composer.json` file if you intend to use the example files.
74+
75+
76+
## Contributing?
77+
Please format your code before creating a pull-request:
78+
79+
vendor/bin/php-cs-fixer fix --level psr2 .
80+
81+
### Special Thanks
82+
This package used [AndreasHeiberg/laravel-messenger](https://github.com/AndreasHeiberg/laravel-messenger) as a starting point.

src/Cmgmyr/Messenger/MessengerServiceProvider.php

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,27 @@
55
class MessengerServiceProvider extends ServiceProvider
66
{
77
/**
8-
* Indicates if loading of the provider is deferred.
9-
*
10-
* @var bool
11-
*/
12-
protected $defer = false;
13-
14-
/**
15-
* Bootstrap the application events.
8+
* Bootstrap the application services.
169
*
1710
* @return void
1811
*/
1912
public function boot()
2013
{
21-
$this->package('cmgmyr/messenger');
14+
$this->publishes([
15+
base_path('vendor/cmgmyr/messenger/src/config/config.php') => config_path('messenger.php'),
16+
base_path('vendor/cmgmyr/messenger/src/migrations') => base_path('database/migrations'),
17+
]);
2218
}
2319

2420
/**
25-
* Register the service provider.
21+
* Register the application services.
2622
*
2723
* @return void
2824
*/
2925
public function register()
3026
{
31-
//
32-
}
33-
34-
/**
35-
* Get the services provided by the provider.
36-
*
37-
* @return array
38-
*/
39-
public function provides()
40-
{
41-
return ['messenger'];
27+
$this->mergeConfigFrom(
28+
base_path('vendor/cmgmyr/messenger/src/config/config.php'), 'messenger'
29+
);
4230
}
4331
}

src/Cmgmyr/Messenger/Models/Message.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function thread()
5252
*/
5353
public function user()
5454
{
55-
return $this->belongsTo(Config::get('messenger::user_model'));
55+
return $this->belongsTo(Config::get('messenger.user_model'));
5656
}
5757

5858
/**

src/Cmgmyr/Messenger/Models/Participant.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
use Illuminate\Support\Facades\Config;
44
use Illuminate\Database\Eloquent\Model as Eloquent;
5-
use Illuminate\Database\Eloquent\SoftDeletingTrait;
5+
use Illuminate\Database\Eloquent\SoftDeletes;
66

77
class Participant extends Eloquent
88
{
9-
use SoftDeletingTrait;
9+
use SoftDeletes;
1010

1111
/**
1212
* The database table used by the model.
@@ -46,6 +46,6 @@ public function thread()
4646
*/
4747
public function user()
4848
{
49-
return $this->belongsTo(Config::get('messenger::user_model'));
49+
return $this->belongsTo(Config::get('messenger.user_model'));
5050
}
5151
}

src/Cmgmyr/Messenger/Models/Thread.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
use Carbon\Carbon;
44
use Illuminate\Database\Eloquent\Model as Eloquent;
55
use Illuminate\Database\Eloquent\ModelNotFoundException;
6-
use Illuminate\Database\Eloquent\SoftDeletingTrait;
6+
use Illuminate\Database\Eloquent\SoftDeletes;
77

88
class Thread extends Eloquent
99
{
10-
use SoftDeletingTrait;
10+
use SoftDeletes;
1111

1212
/**
1313
* The database table used by the model.

src/Cmgmyr/Messenger/examples/MessagesController.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
<?php
1+
<?php namespace App\Http\Controllers;
22

3+
use App\User;
34
use Carbon\Carbon;
45
use Cmgmyr\Messenger\Models\Thread;
56
use Cmgmyr\Messenger\Models\Message;
67
use Cmgmyr\Messenger\Models\Participant;
78
use Illuminate\Database\Eloquent\ModelNotFoundException;
89
use Illuminate\Support\Facades\Auth;
910
use Illuminate\Support\Facades\Input;
10-
use Illuminate\Support\Facades\Redirect;
1111
use Illuminate\Support\Facades\Session;
12-
use Illuminate\Support\Facades\View;
1312

14-
class MessagesController extends BaseController
13+
class MessagesController extends Controller
1514
{
1615
/**
1716
* Just for testing - the user should be logged in. In a real
@@ -41,7 +40,7 @@ public function index()
4140
// All threads that user is participating in, with new messages
4241
// $threads = Thread::forUserWithNewMessages($currentUserId);
4342

44-
return View::make('messenger.index', compact('threads', 'currentUserId'));
43+
return view('messenger.index', compact('threads', 'currentUserId'));
4544
}
4645

4746
/**
@@ -57,7 +56,7 @@ public function show($id)
5756
} catch (ModelNotFoundException $e) {
5857
Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
5958

60-
return Redirect::to('messages');
59+
return redirect('messages');
6160
}
6261

6362
// show current user in list if not a current participant
@@ -69,7 +68,7 @@ public function show($id)
6968

7069
$thread->markAsRead($userId);
7170

72-
return View::make('messenger.show', compact('thread', 'users'));
71+
return view('messenger.show', compact('thread', 'users'));
7372
}
7473

7574
/**
@@ -81,7 +80,7 @@ public function create()
8180
{
8281
$users = User::where('id', '!=', Auth::id())->get();
8382

84-
return View::make('messenger.create', compact('users'));
83+
return view('messenger.create', compact('users'));
8584
}
8685

8786
/**
@@ -122,7 +121,7 @@ public function store()
122121
$thread->addParticipants($input['recipients']);
123122
}
124123

125-
return Redirect::to('messages');
124+
return redirect('messages');
126125
}
127126

128127
/**
@@ -138,7 +137,7 @@ public function update($id)
138137
} catch (ModelNotFoundException $e) {
139138
Session::flash('error_message', 'The thread with ID: ' . $id . ' was not found.');
140139

141-
return Redirect::to('messages');
140+
return redirect('messages');
142141
}
143142

144143
$thread->activateAllParticipants();
@@ -167,6 +166,6 @@ public function update($id)
167166
$thread->addParticipants(Input::get('recipients'));
168167
}
169168

170-
return Redirect::to('messages/' . $id);
169+
return redirect('messages/' . $id);
171170
}
172171
}

src/Cmgmyr/Messenger/examples/views/create.blade.php

Lines changed: 0 additions & 33 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>Packages</title>
8+
9+
<!-- Bootstrap -->
10+
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
11+
12+
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
13+
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
14+
<!--[if lt IE 9]>
15+
<script src="//oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
16+
<script src="//oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
17+
<![endif]-->
18+
<style>
19+
body {
20+
padding-top: 55px;
21+
}
22+
</style>
23+
</head>
24+
<body>
25+
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
26+
<div class="container">
27+
<div class="navbar-header">
28+
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
29+
<span class="sr-only">Toggle navigation</span>
30+
<span class="icon-bar"></span>
31+
<span class="icon-bar"></span>
32+
<span class="icon-bar"></span>
33+
</button>
34+
<a class="navbar-brand" href="/">Packages</a>
35+
</div>
36+
<div id="navbar" class="collapse navbar-collapse">
37+
<ul class="nav navbar-nav">
38+
<li class="active"><a href="/messages">Messages @include('messenger.unread-count')</a></li>
39+
<li><a href="/messages/create">New Message</a></li>
40+
</ul>
41+
</div><!--/.nav-collapse -->
42+
</div>
43+
</nav>
44+
<div class="container">
45+
@yield('content')
46+
</div>
47+
48+
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
49+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
50+
<!-- Include all compiled plugins (below), or include individual files as needed -->
51+
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
52+
</body>
53+
</html>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@extends('layouts.master')
2+
3+
@section('content')
4+
<h1>Create a new message</h1>
5+
{!! Form::open(['route' => 'messages.store']) !!}
6+
<div class="col-md-6">
7+
<!-- Subject Form Input -->
8+
<div class="form-group">
9+
{!! Form::label('subject', 'Subject', ['class' => 'control-label']) !!}
10+
{!! Form::text('subject', null, ['class' => 'form-control']) !!}
11+
</div>
12+
13+
<!-- Message Form Input -->
14+
<div class="form-group">
15+
{!! Form::label('message', 'Message', ['class' => 'control-label']) !!}
16+
{!! Form::textarea('message', null, ['class' => 'form-control']) !!}
17+
</div>
18+
19+
@if($users->count() > 0)
20+
<div class="checkbox">
21+
@foreach($users as $user)
22+
<label title="{!!$user->first_name!!} {!!$user->last_name!!}"><input type="checkbox" name="recipients[]" value="{!!$user->id!!}">{!!$user->first_name!!}</label>
23+
@endforeach
24+
</div>
25+
@endif
26+
27+
<!-- Submit Form Input -->
28+
<div class="form-group">
29+
{!! Form::submit('Submit', ['class' => 'btn btn-primary form-control']) !!}
30+
</div>
31+
</div>
32+
{!! Form::close() !!}
33+
@stop

0 commit comments

Comments
 (0)