I'm a new Laravel developer. I tried to use queues but don't know where to start. I did not find any matches after a google search on this.
This is how I tried to use a queue on my controller:
$date = Carbon::now()->addMinute(1);
Queue::later($date, function(){
CategoryTags::create([
'name' => Helper::nowTimestamp()
]);
});
The function inside Queue gets executed and gives an error like Queue does not exist.
I want to call a queue hourly, what am I doing wrong here? How do I implement this?
Looks like you forgot to define namespace.
use Queue;
Related
Is it possible to create a one time link in Laravel? Once you open the link it expires?
I have created a Temporary Signed Link, but I can open it multiple times. How do I counter it?
There is this package that can help you
https://github.com/linkeys-app/signed-url/
This will generate a link valid for 24hours and for just one click .
$link = \Linkeys\UrlSigner\Facade\UrlSigner::generate('https://www.example.com/invitation', ['foo' => 'bar'], '+24 hours', 1);
The first time the link is clicked, the route will work like normal. The second time, since the link only has a single click, an exception will be thrown. Of course, passing null instead of '+24 hours' to the expiry parameter will create links of an indefinite lifetime.
There maybe a package that provides a functionality like this... always worth looking on Packagelist before building something rather generic like this from scratch. But, it's also not a hard one to build from scratch.
First you'll need database persistence, so create a model and a migration called UniqueLink. In the migration you should include a string field called "slug", a string field called path, and a timestamp field called "used_at."
Next create a controller with a single __invoke(string $slug) method. In the method look up the $link = UniqueLink::where('slug', $slug)->first(); Update the models' used_at parameter like so $link->update(['used_at' => Carbon::now()]);
Then return a redirect()->to($link->path);
Add a route to your routes file like this Route::get('/unique-link/{slug}', UniqueLinkController::class);
Now you'll just need to create a method to add these links to the db which create a slug (you could use a UUID from Str::uuid() or come up with something more custom) and a path that the link should take someone. Over all a pretty straight forward functionality.
You could track when the URL is visited at least once and mark it as such for the user if you really want to, or you could reduce the expiry down to a few mins.
URL::temporarySignedRoute( 'foobar', now()->addMinutes(2), ['user' => 100] );
if any data has been inserted into the database, I want to alert message to another page. How can I do it?
This is the controller page:
public function insertFunction(Request $request) {
$insert = New ExampleTable;
$insert->test_id = $request->id;
$insert->save();
// after this i want to send notification to the another page(panel.blade.php) without refreshing
}
This is the panel.blade.php where I want to see the notification:
<script>
// if notification comes, do it
alert("notification came");
</script>
I'm using mysql. If you help me I will be glad, thanks.
Assuming that you want real time notification, the best practice would be to use the broadcast functionality of Laravel.
Most likely, you will end up using something like pusher.
However, you could make a custom java-script loop that continuously asks your endpoint if there has been any updates, but that would be bad practice and is not recommended.
This is an article that I found helpful. Good luck!
Did my research and found nothing about this topic.
In the docs: https://mailchimp.com/developer/marketing/guides/track-outside-activity-events/#create-an-event
Apparently said how to create an event with options, using the library that they said which in PHP is:
composer require mailchimp/transactional
I can ping, do all the simple requests without problem
but some options for events are not even avaliable, for example:
$options = new \MailchimpMarketing\Model\Events();
there is no 'Model' or Events in that namespace,
then of course I looked how this event is build in other languages and I give a try to pass parameters to the event like this:
$options = ["name" => "my-event-name", "properties" => ['PASSLINK' => 'test']];
$response = $mailchimp->lists->createListMemberEvent(
env('MC_AUDIENCE_ID'),
"somemember#gmail.com",
$options
);
200 status response, Event is trigger, mail received
but in the template used, nothing is passed:
I used in that template that event property like this:
*|EVENT:PASSLINK|*
also tried lowercase
*|EVENT:passlink|*
Same result
don't know what else to do
I had a similar issue. Seems that for a journey, the event property merge tag *|EVENT:PROPERTY|* does not work. They only work for classic automation. May be that is the issue.
Same issue here.
I tried all these combination of EVENT properties.
None of them works..
*|EVENT:name|*
*|EVENT:NAME|*
*|EVENT:PROPERTIES|*
*|EVENT:properties|*
*|EVENT:PROPERTIES:CODE|*
*|EVENT:properties:code|*
I'm trying to setup a simple routing system based on convention.
My app will have this structure
Http
--Controllers
----Admin
------User.php
----Books
------Add.php
----etc...
I want to be able to add new Folders and controllers without adding routes manually to the web.php file.
For example I want the route to respond to /Admin/User URL with User.php controller.
I'm trying something like this, but I don't understand how to write the internal router...
Route::any('/{module}/{action?}', function($module, $action = 'index') {
Route::get('*',$module.'\'.$action.'#index' );
});
It seems that Rout:get('*'... never matches.
PS the controller namespace is correct and I reloaded with composer.
The controller works if called harcoded.
I tried also to escape '\'
$r=$module.'\\'.$action.'\\'.$action.'Ctl#index';
Route::get('/',$r );
But no result. The route is intercepted but nothing i served
It seems I came up with this
Route::get('/{module}/{action}', function($module,$action) {
return App::make('\App\Http\Controllers\\'
.$module.'\\'.$action)->callAction('index', []);
});
Any other better way?
I am pretty new to Laravel. I am working on a REST api and was trying to look at the queries that were being generated from the models. In my routes I have a route group set up.
Route::(["before" => "auth", function()
{
Route::model("juror_subject", "JurorSubject");
Route::get("juror_subject", [
"as" => "juror_subject/index"
"uses" => "JurorSubjectController#index"
]);
});
I wanted to see what query was actually being run. I was watching a video by Jeffrey Way and he mentions that you can use Event::listen to see the query like so.
In routes:
Event::listen('laravel.query', function($sql){
var_dump($sql);
});
However, when I load the url:
localhost:8080/api/juror_subject
It returns the json response and never seems to fire the laravel.query event.
Am I missing some element that is needed to get event listeners to work properly? Is the type of routing I am using not firing a query? If so, how would I go about dumping the queries using a route group?
laravel.query is for Laravel 3 , use illuminate.query instead, also check this answer for more details.
Moreover, call DB::getQueryLog() to get all ran queries ( no need for listener), or use this package which is pretty neat.