Open RaazPuspa opened 4 years ago
Can any one suggest me some sort of solutions here?
@RaazPuspa are the routes working when you visit them manually in your browser? If so then this might be an issue of routes being registered once on boot.
Try calling (new \Hyn\Tenancy\Providers\Tenants\RouteProvider(app()))->boot();
after you identify your tenant.
I found a "hack" to make it work by defining the copy of route inside default routes/web.php
file. I don't know if this is how it is expected to work, but at this moment its working fine for us.
Regarding your suggestion, I added (new RouteProvider(app()))->boot();
after app(Environment::class)->tenant($this->website);
. Still the issue is same, if I remove route definition from default Laravel path.
ICYMI: I am trying to prepare route from a class method invoked by a cron job with Laravel scheduler (once a day).
Following is a screenshot of the route in working. The message is as expected for some random token string.
Would you be able to share the cron job and how you are calling it?
This is the content of schedule()
inside App\Console\Kernel
app(Website::class)->whereHas('activeCustomer')
->each(function ($website) use ($schedule) {
$schedule
->call(new SendCalibrationDueNotification($website))
->name('SendCalibrationDueNotification')
->timezone($this->scheduleTimezone())
->withoutOverlapping()
->runInBackground()
->dailyAt('03:00');
$schedule
->call(new SendCalibrationOverDueNotification($website))
->name('SendCalibrationOverDueNotification')
->timezone($this->scheduleTimezone())
->withoutOverlapping()
->runInBackground()
->dailyAt('03:30');
});
This is how the __invoke
method inside each of the two classes start:
public function __invoke()
{
app(Environment::class)->tenant($this->website);
// method logic
}
Just to confirm it, could you try booting the route provider after identifying the tenant and then immediately try to resolve the route?
Added the following contents just below app(Environment::class)->tenant($this->website);
(new \Hyn\Tenancy\Providers\Tenants\RouteProvider(app()))->boot();
logger(route('profile.unsubscribe.show', ['t' => str_random(64)]));
My crontab entry for the project:
* * * * * cd $HOME/Documents/projects/andatech/calibration && php artisan schedule:run >> /dev/null 2>&1
In the image below, the successful logs are when routes are defined at routes/web.php
and the exception is caught after it had been removed (keeping a single copy in routes/tenants.php
.
Could you dd the ->website()
from the environment as well? Think that's actually empty and that should be the issue.
Also, please double-check, triggering that function might fix your issue.
@ArlonAntonius, yes you got it right. The website from the environment is null. But, triggering the function call does not help me.
As in the image below, the dd
method throws and exception Route [profile.unsubscribe.show] not defined.
when route definition is set only within tenants/routes.php
.
Try setting the hostname, I expect that should solve the problem :)
Hey @ArlonAntonius, I tried to set the environment hostname using ->hostname()
API method from Environment
class. Is that the correct way? if yes, that's not helping me at all. if not, what is the way to set the hostname?
app(Environment::class)->tenant($this->website);
app(Environment::class)->hostname(
$this->website->hostnames()->latest()->first()
);
Using that approach, there are no any issues logged but the intended task did nothing. The cron job is assumed to send 48 emails (today, Mon Aug 31, 2020). When I didn't set the hostname, there are 48 error log entries for route not found
issue but after setting it nothing happened at all.
Description
I have been implementing cron jobs through Laravel scheduler to send some reminder emails for the clients with unsubscription options (link) attached. The job fetches every tenants and for each one select a list of contacts eligible for reminder and send them emails via queue. I have switched the tenant with the following command and can get expected set of contacts from each tenant database, but while using
route()
it pops an error.Actual behavior
InvalidArgumentException: Route [profile.unsubscribe.show] not defined.
Expected behavior
route()
should prepare url as requested as it is defined on theroutes/tenants.php
Information
laravel valet
routes/tenants.php (portion of it)
Error log