This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
complete admin dashboard and some other features
- Loading branch information
1 parent
8623a44
commit 8184181
Showing
39 changed files
with
2,018 additions
and
373 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace App\Events; | ||
|
||
use Illuminate\Broadcasting\Channel; | ||
use Illuminate\Broadcasting\InteractsWithSockets; | ||
use Illuminate\Broadcasting\PresenceChannel; | ||
use Illuminate\Broadcasting\PrivateChannel; | ||
use Illuminate\Contracts\Broadcasting\ShouldBroadcast; | ||
use Illuminate\Foundation\Events\Dispatchable; | ||
use Illuminate\Queue\SerializesModels; | ||
use App\Models\Message; | ||
|
||
class MessageSent implements ShouldBroadcast | ||
{ | ||
use Dispatchable, InteractsWithSockets, SerializesModels; | ||
|
||
public $message; | ||
|
||
/** | ||
* Create a new event instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Message $message) | ||
{ | ||
$this->message = $message; | ||
} | ||
|
||
/** | ||
* Get the channels the event should broadcast on. | ||
* | ||
* @return \Illuminate\Broadcasting\Channel|array | ||
*/ | ||
public function broadcastOn() | ||
{ | ||
$channel = $this->message->from_id != -1 ? 'channel-'. $this->message->from_id : 'channel-'. $this->message->to_id; | ||
return new Channel($channel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
|
||
use App\Models\Message; | ||
|
||
use App\Events\MessageSent; | ||
|
||
class ChatsController extends Controller | ||
{ | ||
|
||
public function __construct() { | ||
$this->middleware('auth'); | ||
} | ||
|
||
public function fetchMessage() { | ||
|
||
$messages = Message::where('from_id', '=', auth()->user()->id) | ||
->orWhere('to_id', '=', auth()->user()->id) | ||
->orderBy('created_at', 'asc') | ||
->get(); | ||
|
||
return response()->json([ | ||
'messages' => $messages, | ||
'success' => true | ||
]); | ||
} | ||
|
||
public function fetchAdminMessage($id) { | ||
$messages = Message::where('from_id', '=', $id) | ||
->orWhere('to_id', '=', $id) | ||
->orderBy('created_at', 'asc') | ||
->get(); | ||
|
||
return response()->json([ | ||
'messages' => $messages, | ||
'success' => true | ||
]); | ||
} | ||
|
||
public function sendMessage() { | ||
$message = new Message(); | ||
$message->from_id = request()->from_id ? request()->from_id : auth()->user()->id; | ||
$message->to_id = request()->to_id; | ||
$message->message = request()->message; | ||
$message->save(); | ||
|
||
broadcast(new MessageSent($message))->toOthers(); | ||
|
||
return response()->json([ | ||
'messages' => $message, | ||
'success' => true | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Message extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = ['from_id', 'to_id', 'message']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.