Member Since 1 Year Ago
4,650 experience to go until the next level!
In case you were wondering, you earn Laracasts experience when you:
Earned once you have completed your first Laracasts lesson.
Earned once you have earned your first 1000 experience points.
Earned when you have been with Laracasts for 1 year.
Earned when you have been with Laracasts for 2 years.
Earned when you have been with Laracasts for 3 years.
Earned when you have been with Laracasts for 4 years.
Earned when you have been with Laracasts for 5 years.
Earned when at least one Laracasts series has been fully completed.
Earned after your first post on the Laracasts forum.
Earned once 100 Laracasts lessons have been completed.
Earned once you receive your first "Best Reply" award on the Laracasts forum.
Earned if you are a paying Laracasts subscriber.
Earned if you have a lifetime subscription to Laracasts.
Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.
Earned once you have achieved 500 forum replies.
Earned once your experience points passes 100,000.
Earned once your experience points hits 10,000.
Earned once 1000 Laracasts lessons have been completed.
Earned once your "Best Reply" award count is 100 or more.
Earned once your experience points passes 1 million.
Earned once your experience points ranks in the top 50 of all Laracasts users.
Earned once your experience points ranks in the top 10 of all Laracasts users.
Replied to Error : Trait Is Not Found (using In Models)
Try giving the full namespace of trait directly in the use statement, like
use App\Models\Services\Permissions\Traits\HasPermissions;
Started a new Conversation How Laravel Autoloads Directories Other Than App?
Inside the composer.json in autoload section we see that
"autoload": {
"psr-4" : {
"App\" : "app/"
}
}
still Laravel loads classes from database, routes, resources, storage, vendor directories.
Can anybody tell how does this work?
Replied to Model Doesn't Get Deleted When Using Deleting Event
I found solution, when I don't use relation in the deleting
event but use DB facade then everything works. (User gets deleted and also comments)
static::deleting(function ($user) {
// $user->comments()->delete();
DB::table('comments')->where('user_id', $user->id)->delete();
DB::table('store_user')->where('user_id', $user->id)->delete();
});
I wonder why it doesn't work when using comments()->delete()
as expected. (User doesn't get deleted)
Replied to Model Doesn't Get Deleted When Using Deleting Event
And it doesn't show any error. But user is not deleted.
Replied to Model Doesn't Get Deleted When Using Deleting Event
User Model does is not deleted. But comments are deleted.
Started a new Conversation Model Doesn't Get Deleted When Using Deleting Event
Hi, deleting
event works but the actual model where delete()
method is being used persists in the database.
This is user controller method
public function delete(User $user)
{
// dd($user);
if (Gate::denies('delete-user', $user)) {
return abort(403);
}
// $user->stores()->detach();
$user->delete();
return redirect()->back()->with('message', "User deleted Successfully!");
}
This is booted method on user model
protected static function booted()
{
static::deleting(function ($user) {
$user->comments()->each(function($comment){
$comment->delete();
});
DB::table('store_user')->where('user_id', $user->id)->delete();
});
}
If I don't use deleting
event or do any other operation before delete then it works well and user gets deleted.
Replied to Notification Table Doesn't Exist Error
@michaloravec I think it uses correct connection when using $user->notify(); and default when using same user class $user->notifications; ! thanks.
Replied to Notification Table Doesn't Exist Error
@michaloravec this solution came to my mind. But shouldn't it work right away?
Started a new Conversation Notification Table Doesn't Exist Error
Hi,
I am facing a strange issue in my project.
I have a separate database for my 'users' table. I want to use notifications for the users.
class User extends Model {
protected $connection = 'myusers';
}
When creating the notification using
$user->notify(new EmailSent());
Laravel searches for 'notfications' table in the database where user table is located. So I migrated notifications table to the 'myusers' database.
But, when I try to get notifications of user
auth()->user()->unreadNotificatins;
This time, laravel searches for notification table in my default connection and throws table not found exception.
Why is this ? When storing notification table requires in Users connection and when reading it can't read from there? When I specify the connection property pointing to notification table in DatabaseNotifications class it works well But it should take automatically from User Model as it reads when creating new notification.
Is it a bug in Laravel? Or Am I doing something wrong
I hope question is understandable. Please answer as I don't want to edit code in vendor directory.
Commented on Union And Pseudo Types
Should I upgrade to php 8 now if I am working on laravel 7.2 and 8 projects?
Commented on The Hue REST API
Cool stuff ! but not really useful because one need to have hardware to work on it. It would be nice to have a series on rest api without any special ingredient requirement.
Replied to How To Filter Paginated Results?
@snapey Thanks for the reply.
I have a little complex condition. When I do it by chaining where method on eloquent I get not a number and various other errors. Can you guide me how should I do this operation please?
where(function($query){
$query->where(((int)'items' - (int)'checked_items') - 'other_item', '>', 3);
})
Replied to How To Filter Paginated Results?
@automica Thanks for reply.
I tried that. But I get error - 'paginate' does not exist. I think it is because after filtering we get a collection and paginate does not exist on collection.
Replied to How To Filter Paginated Results?
@aurawindsurfing Thanks for the reply.
I am trying to do such thing.
$items = $items->paginate(10);
$filtered = $items->filter( function($item) {
if (condition) {
return true;
}
});
Now I want to show the filtered items in view but with pagination links. I hope you got my point. Please reply.
Started a new Conversation How To Filter Paginated Results?
I have an application where I need to filter further the paginated results. When I apply filter method after the pagination method the view gives an error.
I can't insert the logic in sql query because it is complex enough.
How can I paginate and filter the results and pass to view so that pagination also works from there?
Any help appreciated.
Replied to How To Serve VIDEO Files Without Direct Access To File Link?
@bobbybouwmann I have created a controller action which returns the link to mp4 file. But how do I connect that stream with html element. If I place the route in src then it's just that route and not the mp4 source.
Started a new Conversation How To Serve VIDEO Files Without Direct Access To File Link?
Hello,
I want to play videos on a particular page of my website. Already implied Auth middleware.
Currently, I can copy the video source file and play it in different tab as a get request. Basically, as we use images and logos in project using assets.
But, I don't want user to copy the video source link and play video in different tab. I don't want video to be played outside of my page.
I am using html element and source property updated using javascript. How should I proceed?
Replied to Javascript Events Sometimes Don't Work
Is it because that element is dynamically generated? I guess, In that case it shouldn't work at all.
Replied to Javascript Events Sometimes Don't Work
@bugsysha Thanks for the reply! It is a single video element not multiple. The video element is dynamically added inside a modal.
Started a new Conversation Javascript Events Sometimes Don't Work
Hello,
In my application I am using javascript video element events like, onplaying, onpause, onstalled etc.
The problem is, these elements do not get fired everytime. It works good and after sometime it doesn't. Using the same browser. Tried in different browsers, sometimes events fire, sometimes don't.
The video elemnt is dynamically created and it is inside a modal. The modal is shown after video element is created inside it's body. This all is a part of ajax request success method of jquery.
I have tried to add event listeners after adding the dynamic html. I have also tried to attach listners immediately after document is ready.
I have attached some code..
$('#abcModalBody').empty();
// console.log("Body emptied");
// AJAX request
$.ajax({
url: '/abc/url',
type: 'post',
data: {transId: id},
success: function(response){
data = JSON.parse(response);
if(addHtmlToModal()) {
addVideoEventListeners();
// Display Modal
$('#abcModal').modal('show');
}
}
})
function addVideoEventListeners() {
video = document.getElementById('video');
// console.log(video);
fillItemsTime();
if (video && firstItemsTime() > 0) {
video.onplay = function() {
// alert("Play event fired");
console.log('play event fired');
}
video.onplaying = function() {
startDisplay();
}
video.onpause = function() {
// console.log("Paused");
clearTimeout(timer);
}
video.onwaiting = function() {
// console.log("waiting event fired");
clearTimeout(timer);
}
video.onstalled = function() {
clearTimeout(timer);
}
video.onseeking = function() {
// console.log("seeking");
clearClassesOfAllRows();
clearTimeout(timer);
}
video.onended = function() {
index = 0;
clearClassesOfAllRows();
}
}
// console.log("Before play");
video.oncanplaythrough = function() {
// console.log("video can be played now");
$('#video').get(0).play();
}
}