Laravel Queue mail doesn't work, but send mail works - laravel

i have a very strange problem.
If i use laravel send mail everything works perfect.
but when i queue a mail it give a this error.
but the very strange part is, that yesterday my code did work!! without changing anything now
this works:
Mail::send('emails.empty',
$invoice, function ($m) use ($invoice) {
$m->from('hello#app.com', 'Your Application');
$m->to($invoice['customer_email'], $invoice['customer_name'])
->subject($invoice['email_subject']);
});
But this doesn't work
Mail::later(1, 'emails.empty',
$invoice, function ($m) use ($invoice) {
$m->from('hello#app.com', 'Your Application');
$m->to($invoice['customer_email'], $invoice['customer_name'])
->subject($invoice['email_subject']);
});
Also with the new 5.3 way it doesn't work
$user = new App\User();
$user = $user->find(1);
Mail::to($user)->queue(new EmailTest($user));
This is the faild job error:
Swift_TransportException: Expected response code 250 but got code "", with message "" in /private_html/dev1/vendor/swiftmailer/swiftmailer/lib/classes/Swift/Transport/AbstractSmtpTransport.php:383
Stack trace:
#0 .......................
I use mailtrap to send/catch my emails. with the same settings de SEND function works! so its not the settings

Related

laravel bad request status message in console

can someone help me how can I pass error code and message to be able to parse it in a console for example...
in my case - if I don't set any status code it will return status code 200(even tho I use rules for validation) and I can see my custom message in the console logs
but when I set 400 status code I get a generic message
public function store(StoreNewTeam $request)
{
$validator = Validator::make($request->all(),
['team.name' => 'required|unique:teams,name',
'team.level' => 'required',
'teamMembers.*.firstName' => 'required',
'teamMembers.*.lastName' => 'required',
'teamMembers.*.email' => 'required|unique:team_members,email',
]);
if ($validator->fails()){
return response()->json(['message' => $validator->errors()->first()],Response::HTTP_BAD_REQUEST);
}
but when I go to network tab I can see my custom message...
how can I get that message to console?
and additional question... if I work on API like that is it OK to stay that way since I can see my message in network tab - as well in postman?
edit:
StoreNewTeam is empty - just authorise is changed to true
since my request is array of 2 data combined I wanst able to type rules inside of StoreNewTeam
so issue was not inside of laravel, but in my axios setup
to parse error in console axios error should be set up like this
.catch(function (error) {
console.log(error.response);
});

Laravel Echo Server can not be authenticated, got HTTP status 403

I got laravel-echo-server and Laravel 5 application with vuejs, and I'm trying to connect front end to back end via sockets.
I've managed to connect everything together via Echo.channel() method, however it will not subscribe with Echo.private()
This is what I got so far :
Once the page loads I call :
I initilise the Echo via
window.Echo = new Echo({
broadcaster: 'socket.io',
host: window.location.hostname + ':6001',
csrfToken : Laravel.csrfToken,
auth : {
headers : {
Authorization : "Bearer b6f96a6e99e90dzzzzzzz"
}
}
});
Then I create a new event via vue resourse
Vue.http.get('/api/errors/get');
This fires laravel event(new \App\Events\ErrorsEvent()); event
Which Broadcasts the event privately via
public function broadcastOn()
{
return new PrivateChannel('errors');
}
At this point laravel-echo-server responds with
Channel: private-errors
Event: App\Events\ErrorsEvent
CHANNEL private-errors
Then i try to subscribe to the channel with echo by running
Echo.private('errors')
.listen('ErrorsEvent', (e) => {
this.errors = e.errors;
console.log(e);
});
At which laravel-echo-server responds with
[14:47:31] - xxxxxxxxxxxxxx could not be authenticated to private-errors
Client can not be authenticated, got HTTP status 403
Does anybody know if I'm missing something here?
EDIT
This is my BroadcastServiceProvider
public function boot(Request $request)
{
Broadcast::routes();
/*
* Authenticate the user's personal channel...
*/
Broadcast::channel('App.User.*', function ($user, $userId) {
return (int) $user->id === (int) $userId;
});
}
Also, I've discovered that if I try to subscribe to
Echo.private('App.User.2')
.listen('ErrorsEvent', (e) => {
this.errors = e.errors;
console.log(e);
});
It connects and everything is ok, however it still refuses to connect with the errors channel
My issue was that I hadn't noticed there are two BroadcastServiceProvider::class entries in app/config.php
I had only checked the first one. Once I uncommented App\Providers\BroadcastServiceProvider::class I didn't need to specify the bearer token.
I believe the reason you couldn't connect on the errors channel in your above config is that you need to change your call in your BroadcastServiceProvider (or routes/channels.php) to
Broadcast::channel('errors', function ($user) {
return true; //replace with suitable auth check here
});

Laravel Tinker is using old values from database

I've updated a webhook URL in my database, but when I try to spawn an event in Laravel Tinker that should post a message to a slack channel, it's using the "old" testing URL and not the new URL from the database.
Each store has a one-to-many relationship to a slack integration.
>>> foreach ($store->slackIntegrations as $integration) { print $integration->webhook_url; }
https://hooks.slack.com/services/T0K572A2W/B8R8MPMV2/XXXX
When an invite event is spawned, with the id of the store_invite a notification should be posted to the configured slack channel.
>>> $e = new \App\Events\InviteEvent(179605);
=> App\Events\InviteEvent {#1005
+body: 179605,
+socket: null,
}
>>> event($e);
GuzzleHttp\Exception\ClientException with message
'Client error: `POST
https://hooks.slack.com/services/T0K572A2W/B30D7AV52/XyzXyz`
resulted in a `404 Not Found` response: No service'
/**
The above endpoint URL is invalid and no longer set in the database.
*/
The event logic is as follows.
public function handle(InviteEvent $event)
{
// This fetches the ids in the event body.
$ids = $this->getIds($event);
$store_invites = Invite::with(['store' => function ($q) {
$q->withoutGlobalScopes();
}])->find($ids);
$invites_to_slack = $store_invites->filter(function ($invite) {
return $invite->shouldSlack();
});
$invites_to_slack->each(function ($invite) {
$invite->sendToSlack();
});
}
This was an issue with me not having updated the same Database as the project .env file was referring to.

BroadcastException 404 NOT FOUND in PusherBroadcaster.php (line 106)

First time I've ever posted here for laravel help! I'm trying to get Broadcast events working on Laravel 5.4 with pusher
When I set the broadcast driver to 'log' I am successfully getting the details in the log so I know most things are working. However its the broadcasting that is the issue. When i set things to pusher I am getting a 404 File not found exception
BroadcastException
404 NOT FOUND
in PusherBroadcaster.php (line 106)
I have
"pusher/pusher-php-server": "^2.6",
in the composer.json
and all the keys etc are in the .env file
The method being called in PusherBroadcaster.php is
` public function broadcast(array $channels, $event, array $payload = [])
{
$socket = Arr::pull($payload, 'socket');
$response = $this->pusher->trigger(
$this->formatChannels($channels), $event, $payload, $socket, true
);
if ((is_array($response) && $response['status'] >= 200 && $response['status'] <= 299)
|| $response === true) {
return;
}
throw new BroadcastException(
is_bool($response) ? 'Failed to connect to Pusher.' : $response['body']
);
}`
and its the response['body'] which has the "404 FILE NOT FOUND" response so it looks like its something to do with connecting to pusher
This is my first broadcast with pusher so Im a newb as far as this is concerned.
Help ;-)

Laravel JWT Auth Token invalid / Signature could not be verified

I'm getting pretty tired of this error.. Stuck for 2 days now.
I do receive a token on valid credentials, but my token stays invalid, no matter if I pass it through url parameter (?token=[token]) or as Auth header (Bearer: [token]).
Anyone still experiencing this? I followed everything in the tutorial. Also configured both .htaccess in my public folder, and in my apache configuration.
Route::get('/test', function () {
return JWTAuth::parseToken()->authenticate();
});
Going to this route returns
TokenInvalidException in NamshiAdapter.php line 71:
Token Signature could not be verified.
For lookups, here is my authentication method from my AuthController.php
public function authenticate(Request $request) {
$credentials = $request->only('email', 'password');
$user = User::where('email', Input::get('email'))->first();
try {
if (!$token = JWTAuth::attempt($credentials)) {
return $this->respondUnauthorized();
}
} catch (JWTException $e) {
return $this->respondInternalError('Could not create token!');
}
// dd()
return $this->respond([
'token' => compact('token'),
'user' => $user]);
}
My routes middleware group:
Route::group(['middleware' => ['jwt.auth', 'jwt.refresh']], function() {
When I check line 71 in my NamshiAdapter and I dd() my token it says my secret is empty...
There must be something wrong? Is this just a minor bug or am I missing something?
in Laravel 5.5 (in my case):
1- Run the command:
php artisan jwt:secret
you should see this result:
jwt-auth secret [mygeneratedsecret] set successfully.
2- copy the secret, which is between the bracket (mygeneratedsecret) and add it to the .env file as following:
JWT_SECRET=mygeneratedsecret
3- Make sure your configuration file jwt.php has the secret set as following:
'secret' => env('JWT_SECRET'),
Important Note:
Don't forget to Re-generate the Token (using your login script or whatever you use), because the old token (before the secret configuration)
will still be invalid against the new secret
Happy Coding :)
I had the same issue
the solution is what jycr753 have said... "setting the api secret in jwt.php"
in fact on config/jwt.php, there is the line'secret' => env('JWT_SECRET'),,
Generate the key with this helper php artisan jwt:generate (for some reason I dont know why it doesnt set in the .env file itself like php artisan key:generate).
Copy the key (jwt-auth secret [DSvO98YtJ0204mBu9zqWN9QOMX7Tmvr9] set successfully.) without the bracket and add it in .env file like JWT_SECRET=DSvO98YtJ0204mBu9zqWN9QOMX7Tmvr9 or you can change it straigth in jwt.php secret' => env('DSvO98YtJ0204mBu9zqWN9QOMX7Tmvr9')

Resources