kitten

kitten

Member Since 1 Month Ago

Experience Points
670
Total
Experience

4,330 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
3
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    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.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
670 XP
Oct
14
2 weeks ago
Activity icon

Replied to What's The Best Approach?

I see now, thank you :)

Activity icon

Started a new Conversation What's The Best Approach?

I can't find much info about this, so I am wondering, what the best approach?

A:

$theClass = app('cache');

or B:

$theClass = app()->get('cache');

Can someone shed some light on this, please?

TIA

Sep
25
1 month ago
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

It's okay, no worries :)

Here is something else you can try:

public function getContact($id){

    $data = DB::table('customer_contacts')->where("id",$id)->get();

	return json_encode(  (array)$data );
}

having access to the git repo won't help too much unless I can install the application so I could have an instance running upon which I can test :)

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

I use ajax in every project I have and to be honest, this never happened to me.. so I'm pretty much out of ideas..

If you want, I can have a look over team viewer f that's okay with you (you could send me the credentials through email ****@gmail.com)

Other than that I can't think of anything else :(

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

do you have a model for the customer_contacts table? you could simply change it to:

return CustomerContact::find($id)->toJson();

if that doesn't solve it, then your last resort is to process to send the response as array and update the js success function like in my example

public function getContact($id){

    $data = DB::table('customer_contacts')->where("id",$id)->get();

	return json_encode( [ 'data' => compact($data) ] );
}

and js:

success: function (response) {
	var data = response.data;

	// this should be a valid json object
	console.info('data', data);

	//#! you should see the email address now
        console.info('email', data.email);

                $('input[name="email"]').val(data.email);
        $('input[name="number"]').val(data["phone"]);
	},
},

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

Have you tried my example? with the collection change to array? or better yet, to json?

// with your existent js success code
public function getContact($id){

    return DB::table('customer_contacts')->where("id",$id)->toJson();

}

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

hmm..

try this:

public function getContact($id){

    $data = DB::table('customer_contacts')->where("id",$id)
    ->get();

    return [  'data' => json_encode($data) ];

}

and in your success function:

success: function (response) {
	var data = response.data;

	// this should be a valid json object
	console.info('data', data);

	// if this doesn't show up you should change how you respond (in your controller, instead of serializing the collection, transform it to array and this should work afterwards)
        console.info('email', data.email);

                $('input[name="email"]').val(data.email);
        $('input[name="number"]').val(data["phone"]);
	},
},

Activity icon

Replied to Help... Livewire Setup

Ah, yes! So easy to overlook :)

Great to hear you got it working!

Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

can you please post the ajax code part, please? It would be easier for me to see what might be wrong, otherwise i could keep guessing..

Things to make sure:

  • Your ajax endpoint exits with a json encoded string, something like this:
exit( json_encode( [ 'data' => ['your response data] ] ) );
  • your ajax request config includes (but not necessarily) the dataType:
$.ajax({
...
dataType: 'json',
})
.done(function(r){ /* here you can access: r.data since data is the "key" of your response object */ })
.error(function(x,s,e){})
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

hmm,... your code should work, as well s data.fieldName..

can you try to output in console this and see if you get the email?

// in the success function
done(r){
	if(r){
		console.info(r.data.email);
	}
}

Activity icon

Replied to 1 Instance Of Laravel With Multiple Subdomains

Then -> routing...

Group specific routes and you're all set

Activity icon

Replied to Help... Livewire Setup

If this is an admin protected route then I guess you need to pass the token to the request as well (I don't have much experience with livewire) so maybe you should look into that

Activity icon

Replied to 1 Instance Of Laravel With Multiple Subdomains

Not sure I fully understand the question, but:

  • if you don't have a laravel setup on each (sub)domain then you can achieve that through routes
  • if you have a laravel instance on each of them then all you need to do is setup the app url in your env file
Activity icon

Replied to Solved: Ajax Request Data Returns As Object - How To Populate Multiple Inputs?

How does the response look like? can you post here an example, please?

Also, you can easily transform that to a livewire component, so no hassle in parsing the response and showing validation messages, etc.. https://laracasts.com/series/livewire-basics/episodes/1

Activity icon

Replied to How To Get Last Row From Table From A User

Hi!

Try

$movements = DB :: table ('movements')
         -> where ('movements.user_id', Auth :: user () -> id)
     -> latest()->first();

Sep
24
1 month ago
Activity icon

Replied to Retrieve Posts From Categories Except One

:)

I agree, I've got to a somewhat close version too :)

The only difference is here

$privateSubcategories = [$privateCategory->id] + $privateCategory->childrenCategories()->pluck('id');

I don't like merging arrays using "+", but that's just a personal preference, nothing more :)

Thanks a lot!

Activity icon

Replied to Retrieve Posts From Categories Except One

I got it..

$postStatusID = PostStatus::where( 'name', 'publish' )->first()->id;
        $postTypeID = PostType::where( 'name', 'post' )->first()->id;

        $privateCatID = 0;
        $subcategories = [];
        if ( defined( 'NPFR_CATEGORY_PRIVATE' ) ) {
            $privateCat = npfrGetCategoryPrivate();
            $privateCatID = $privateCat->id;
            $subcategories = Arr::pluck( $privateCat->childrenCategories, 'id' );
        }

        $query = Post::with( [ 'categories' => function ( $query ) use ( $privateCatID, $subcategories ) {
            $query->whereNotIn( 'categories.id', [ $privateCatID, ...$subcategories ] );
        } ] )
            ->whereDoesntHave( 'categories', function ( $query ) use ( $privateCatID, $subcategories ) {
                $query->whereIn( 'categories.id', [ $privateCatID, ...$subcategories ] );
            } )
            ->where( 'post_status_id', $postStatusID )
            ->where( 'post_type_id', $postTypeID )
            ->whereDate( 'created_at', '>', now()->subMonth()->toDateString() )
            ->limit( $number )
            ->inRandomOrder()
            ->get();

        return $query;

Thank you so much for your help, I appreciate it!

Activity icon

Replied to Retrieve Posts From Categories Except One

I guess my last reply stands because I've just tried your last example and there is no change :(

So while this query works, it just doesn't under my specific condition

Activity icon

Replied to Retrieve Posts From Categories Except One

The problem is that I need to exclude (somehow) the children of the Private category because from what can see here, only posts directly inside the specified $privateCatID are ignored, the posts from the children of the Private category are still picked up..

Activity icon

Replied to Retrieve Posts From Categories Except One

I get posts, but they include posts from the Private category, as shown here: [screenshot removed]

Activity icon

Replied to Retrieve Posts From Categories Except One

without categories.id I get this: [screenshot removed]

with categories.id I get what I'vve shown you in the previous screenshot

I guess, in the end, I could get some random posts from a specific public category... Not what I wanted but I want to keep some hair on my head :(

PS I've updated to "now()->subMonth()->toDateString();", still no change

Activity icon

Replied to Retrieve Posts From Categories Except One

I've updated the query, but it still doesn't work :(

[screenshot removed]

It really drives my crazy :(

Activity icon

Replied to Retrieve Posts From Categories Except One

Okay, so this is, updated since I've realized there is more to it than I initially thought:

Categories:

NASA
Private
	> USA

Posts

Florida , category: USA
Post 1, cat: NASA
Post 1000, cat: NASA

now, using the updated code:

$query = Post::with( [ 'categories' => function ( $query ) use ( $privateCatID ) {
            $query->where( 'categories.id', '<>', $privateCatID );
        } ] )
            ->whereDoesntHave('categories', function ($query) use ($privateCatID) {
                $query->where('categories.id', '<>', $privateCatID);
            })
            ->where( 'post_status_id', $postStatusID )
            ->where( 'post_type_id', $postTypeID )
            ->whereDate( 'created_at', '>', now()->subMonth() )
            ->limit( $number )
            ->inRandomOrder()
            ->get();

the query doesn't return any posts...

I guess I need to look in the current category's parents and see if the id matches the privateCatID

Activity icon

Replied to Retrieve Posts From Categories Except One

It gave me an error on that line so I have removed it, but now I've had another close look at the db and something doesn't look quite right, because the category I'm trying to exclude is actually the parent of the post's category.

I need a minute to work on this and I'll get back to you

Activity icon

Replied to Retrieve Posts From Categories Except One

[screenshot removed]

Florida, for example is part of the Private category

Activity icon

Replied to Retrieve Posts From Categories Except One

Thank you for your prompt response!

I've just tried it and it doesn't work :( It still gets posts from the Private category :( I wish I could include a screenshot :(

I have updated your example to this (since I don't have comments)

$privateCatID = 0;
        if ( defined( 'CATEGORY_PRIVATE' ) ) {
            if ( $privateCat = getCategoryPrivate() ) {
                $privateCatID = $privateCat->id;
            }
        }

        $query = Post::with( [ 'categories' => function ( $query ) use ( $privateCatID ) {
            $query->where( 'categories.id', '<>', $privateCatID );
        } ] )
            ->where( 'post_status_id', $postStatusID )
            ->where( 'post_type_id', $postTypeID )
            ->whereDate( 'created_at', '>', now()->subMonth() )
            ->limit( $number )
            ->inRandomOrder()
            ->get();
Activity icon

Started a new Conversation Retrieve Posts From Categories Except One

Hello!

I'm at my wits end all I have left is pulling my hair :(

My setup is as following: I have Posts & Categories as a many to many relationship

What I need: Select a given number of posts from all categories but one (let's call it Private).

I've tried everything and nothing works and it drives me crazy!!!

One possible solution would be to select all posts and then loop over the collection and exclude the posts found in the Private category but I don;t want to do that since I have a site where I'm collecting data from various sources and every hour I get like 1k+ posts so this is not acceptable so I want to do it in one query yet the solution eludes me :(

This is an example of "not working":

$query = Post::with(['categories' => function($q){
            if ( defined( 'CATEGORY_PRIVATE' ) ) {
                if ( $privateCat = getCategoryPrivate()) {
                    $q->where( 'categories.id', '!=', $privateCat->id );
                }
            }
            return $q;
        }])->where( 'post_status_id', $postStatusID )
            ->where( 'post_type_id', $postTypeID )
            ->whereDate( 'created_at', '>', Carbon::now()->subMonth() )
            ->limit( $number )
            ->inRandomOrder()
            ->get();

Can anyone help, please?

TIA