You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<?php
namespace App\Jobs;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Ably\AblyRest;
class AblyJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
private $message;
private $channelName;
/**
* Create a new job instance.
*/
public function __construct($message, $channelName)
{
$this->message = $message;
$this->channelName = $channelName;
}
/**
* Execute the job.
*/
public function handle(): void
{
$ably = new Ably\AblyRest(env('ABLY_KEY'));
$channel = $ably->channels->get($this->channelName);
$channel->publish('message', $this->message);
}
}
<?php
namespace App\Livewire\Message;
use Livewire\Component;
use App\Models\Message;
use Illuminate\Support\Facades\Auth;
use Illuminate\Contracts\View\View;
use Livewire\Attributes\Validate;
use Livewire\WithFileUploads;
use App\Events\Message\PublicMessageEvent;
use App\Models\User;
use App\Jobs\AblyJob;
class CreateMessage extends Component
{
use WithFileUploads;
public int $userId;
#[Validate('required', message: 'Please provide a message')]
public $body;
public $file;
public $channelName = 'public-channel'; // Ably channel name
public function rules()
{
return [
'body' => 'required',
'file' => 'nullable|max:2048',
];
}
public function save()
{
$this->validate(); // Validate the data
if ($this->file) {
$message = Message::create([
'user_id' => Auth::id(),
'body' => $this->body,
]);
foreach ($this->file as $file) {
$message->addMedia($file->getRealPath())->toMediaCollection('media');
}
} else {
$message = Message::create([
'user_id' => Auth::id(),
'body' => $this->body,
]);
AblyJob::dispatch($message, 'public-channel');
}
$channel = $ably->channels->get($this->channelName);
$channel->publish('message', $message);
broadcast(new PublicMessageEvent($this->channelName, $message));
// Random user select karne ke liye
$randomUser = User::inRandomOrder()->first();
$this->userId = $randomUser->id;
$this->body = '';
$this->file = [];
return back();
}
public function render():View
{
$messages = Message::with('user')
->latest()
->take(10)
->get()
->sortBy('id');
return view('livewire.message.create-message',compact('messages'));
}
// Delete
public function delete(int $messageId): void
{
$message = Message::where('id', $messageId)
->where('user_id', Auth::id()) // Ensure message belongs to the current user
->first();
// Delete the message if it exists
if ($message) {
$message->clearMediaCollection('media');
$message->delete();
}
}
public function rotateRandomUser()
{
$randomUser = User::inRandomOrder()->first();
$this->userId = $randomUser->id;
}
public function publishMessage($message)
{
$ably = new AblyRealtime(env('ABLY_KEY'));
$channel = $ably->channels->get($this->channelName);
$channel->publish('message', $message);
}
}
ably/ably-php": "^1.1",
ABLY_KEY=my key
BROADCAST_DRIVER=ably
ABLY_DISABLE_PUBLIC_CHANNELS=true
ABLY_TOKEN_EXPIRY=21600
ABLY_SYNC_SERVER_TIME=true
![Capture](https://github.com/user-attachments/assets/fa1c97e8-8673-47c9-88bb-9964dec59688)
![Capture1](https://github.com/user-attachments/assets/9225e54f-7143-40ab-978f-e97c317b668b)
Php version PHP 8.1.17
Laravel Framework 10.48.22
Any one help me i will make a project use Laravel
┆Issue is synchronized with this [Jira Task](https://ably.atlassian.net/browse/ECO-5092) by [Unito](https://www.unito.io)
The text was updated successfully, but these errors were encountered:
It seems, you are directly using AblyRest instance, you might like to use https://github.com/ably/ably-php-laravel package instead. Also, ably-php only supports REST API, it doesn't support REALTIME.
ably/ably-php": "^1.1",
The text was updated successfully, but these errors were encountered: