Laravel 4.2 Email::queue with assets - laravel

Simple, I am trying to queue an email using services beanstalkd and supervisord like so:
Mail::queue('emails.congratulations', $user, function($message) use($user) {
$message->to($user['email'], $user['name'])
->subject('Congratulations!');
});
My supervisor program config:
[program:emailservice]
command=php /path/to/laravel/artisan queue:listen
stdout_logfile=/path/to/laravel/app/storage/logs/emailservice_supervisord.log
redirect_stderr=true
In my blade file I am trying to access an asset, an image:
<p>
<img src="{{ asset('assets/img/logo.png') }}" />
</p>
When the email is sent and received, the image is broken and the URL to the image looks like this:
<img src="http://:/assets/img/logo.png"/>
I cannot figure out why the domain is :
If anyone else as experienced this behavior it would be good to get this out in the open because I have scoured Google and StackOverflow for answers to this issue without any mention of the issue.
A question I ask myself... when queuing, is Laravel/Supervisor/Beanstalk smart enough to remember the domain for the job?

You have to set application url to your domain (http://localhost by default) in config/app.php.

Related

Laravel Telescope is not working in production with Laravel Voyager. How to secure /telescope/* routes in Laravel 7?

I'm using Laravel with Auth, Auth UI, Voyager admin panel, Telescope. Everything works fine untill I change APP_ENV=local to APP_ENV=production in .env file. When I change the .env file to production then I get the below error. screen shot of my issue is here.
Trying to get property 'name' of non-object
Basically I want to protect /telescope/*routes in production. But before doing that I am getting this error.
I read the same issue in github similar issue github link. I think the answer is present in the link but im unable to digest it as im a newbie.
Any help to fix this, and protecting telescope routes in production is much appreciated. I tried to create a Policy and give read permissions to the user via policy. But somehow im not able to fix it.
ok: its too easy - the only thing you have to do is:
php artisan make:policy -m User UserPolicy
thats it.
You can pass the array of email into the gate method in the TelescopeServiceProvider.php
Gate::define('viewTelescope', function ($user) {
return in_array($user->email, [
'username#domain.com'
]);
});
This will block everyone except the mentioned email of logged-in user.

Problem with Laravel routes - all sub folder traffic ending up in route view

Sorry - was difficult to give this one a clear title! But I have an issue and a difference between how my local laravel install is dealing with some routes compared to my live server.
Locally, I have this working:
Route::get('/blog', 'BlogController#home');
Route::get('/blog/{post_slug}', 'BlogController#viewPost');
As you can probably guess, I want to serve up a list of posts via the home() function if /blog is hit. Then all other traffic with a "slug" after /blog/, I want to load the blog post.
This all works locally.
However on live,
/blog/my-blog-post
Is serving up the home() function every time.
Where would I start with debugging this. Laravel versions? Server caching?
Maybe you can do this in laravel 5.7+
Route::prefix('blog')->group(function () {
Route::get('/', 'BlogController#home');
Route::get('/{post_slug}', 'BlogController#viewPost');
});
before just use: php artisan optimize, to clear all cache route and config.
for more info see the docs

Laravel display a custom message in Maintenance Mode

I'm checking out Laravel docs for Maintenance Mode:
https://laravel.com/docs/5.3/configuration#maintenance-mode
When you execute the command php artisan down, it will put the application under maintenance mode, and return the 503.blade.php view.
Works good, but there is an option I can't really make work.. when I do:
php artisan down --message='Upgrading Database' --retry=60
I want to display the message in the view, I tried accessing the obvious choice with {{ $message }} without success, returns undefined variable.
My question is: how to access it?
Actually you don't need that "json_decode" stuff, as all the "error" views (including 503.blade.php) have $exception variable.
So you may just use {{ $exception->getMessage() }} in your view and you will get the exact value that you have passed to artisan down --message command.
By default 503.blade.php view doesn't use this message.
This message is available in a JSON formatted file named storage/framework/down generated by php artisan down command.
You could do something like this to access the directly the message in your view:
{{ json_decode(file_get_contents(storage_path('framework/down')), true)['message'] }}
A cleaner way is to use the $exception variable and include in your view {{ $exception->getMessage() }} like suggested in this answer.
Under the hood, the CheckForMaintanceMode middleware reads the message and other data from the file and thrown a MaintanceModeException with this data.
Edit: After Laravel 8, the payload that creates the storage/framework/down command has changed and doesn't include the exception message. You should use the {{ $exception->getMessage() }} instead on Laravel 8+.
If you want detailed information (not just message) on your maintenance page, you can also use $exception->retryAfter(Int), $e->willBeAvailableAt(Carbon) and $e->wentDownAt(Carbon).
Of course you need to set --retry parameter in artisan command.

Pusher on route not sending event in Laravel

I am creating a test app using Pusher for real-time notification on Laravel 4.
As I am testing the said API, I am having difficulties on making it work.
I have this on my routes.php:
Route::get('pusher-test', function(){
return View::make('pages.test');
});
Route::any('test', function(){
$pusher = new Pusher('key','sect','app_key'); //my keys are correct.
$pusher->trigger('notificationChannel', 'userRegistration', []);
});
Then my pusherTest.js file:
(function(){
var pusher = new Pusher('key');
var channel = pusher.subscribe('notificationChannel');
channel.bind('userRegistration', function(data){
$('.test').append('HEY!');
});
})();
My view page:
<html>
<head>
<meta charset="utf-8">
{{ HTML::style('_/css/bootstrap.css') }}
{{ HTML::style('_/css/mystyle.css') }}
</head>
<body>
<h2>HI!</h2>
<div class="test"></div>
{{ HTML::script('_/js/bootstrap.js') }}
{{ HTML::script('_/js/jquery.js') }}
{{ HTML::script('_/js/pusher/pusher.min.js')}}
{{ HTML::script('_/js/pusherTest.js')}}
</body>
</html>
When I try to observe the Debug Console of my app on Pusher.com,
here's what I see:
But when I hit the test route, it is not sending an event on my Pusher app, neither it sends the API message to my client. But if I will use the Create new Event tester on debug console, sure enough it sends the API message and my client receives and updates it.
What do you think is happening why on my route it can't send the event to my pusher app? I can't figure it out because is has no exception error. Please advice.
for me it was because I used the eu server and laravel is configured automatically on us server
To expand on #adutu's answer, you need to set
'cluster' => 'eu'
Inside the 'options' section of the Pusher driver configuration, in broadcasting.php.
There are three points at which you can debug your integration with Pusher:
Your interactions with Pusher's HTTP (REST) API
Ensuring events are being received by Pusher using the Pusher Debug Console
Ensuring your client integration is working by checking pusher-js logging
In your situation you've done 2. and you can see the events you are triggering aren't reaching the debug console. So, you need to do 1.
The Pusher PHP Server library provides details of how to enable debugging:
https://github.com/pusher/pusher-php-server#debugging
And how to get log information from the library:
https://github.com/pusher/pusher-php-server#logging
Once you have the pusher-php-server library logging information please feel free to post it so we can see what the problem may be e.g. are you getting a non 2xx response code?
The issue with this is due to the fact that you cannot set the host for the pusher broadcasting.
You only get this issue when you are using the EU cluster, in which case, you should change the host to:
api-eu.pusher.com
Similarly, you can make a custom broadcast driver. that does the same thing as the default one but sets the host parameter.
I am going to suggest an edit to the illuminate broadcast manager to make this change easier to make.

Validating SSL Seal in the Browser in Magento with http:// references

So, one of my developers used a function like this to make a custom navigation for a Magento eCommerce site:
<li><a class="about" href="<?php echo $this->getUrl() ?>"><?php echo $this->__('about') ?></a></li>
The only problem is it's outputting like:
<li>about</li>
From what I understand, SSL seals break in the browser if there are both http:// and https:// references.
I'm trying to look for a quick fix to remedy this and would be thrilled if someone has a better way to do this than what's been done.
Cheers!
Revised:
Thanks guys,
I think I've narrowed it down to an extenstion that was installed called, Jirafe.
The output code is:
<noscript><p><img src="http://data.jirafe.com//piwik.php?idsite=#####" style="border:0" alt="" /></p></noscript>
The php file that I think generates the script is:
class Fooman_Jirafe_Model_JirafeTracker extends Piwik_PiwikTracker
{
protected function sendRequest($url)
{
$client = new Zend_Http_Client($url);
$response = $client->request();
//check server response
if ($client->getLastResponse()->isError()) {
throw new Exception($response->getStatus() .' '. $response->getMessage());
}
return $response;
}
}
How would I request the image via SSL?
Thanks in advance!
You can use
$this->getUrl('', array('_secure' => true));
or
$this->getUrl('', array('_forced_secure' => true));
to make Magento use the configured web/secure/base_url.
I don't believe there is a problem with having non-ssl links on a secure web-page, after all you might wish to link to another website that doesn't support ssl traffic. I think perhaps you can confusing this with including non-secure resources on a page. So in your example I don't believe the anchor link is a problem, but if it was an img tag with a src attribute, then it would cause issues, since you are telling the browser to request an insecure link on a secure page.

Resources