Contents:
do yu have debugbar installed ?
Telescope isnt good?
How do you write it in one line?
you know what scope is ?
It does what I want?
do yu have debugbar installed ?
Telescope isnt good?
How do you write it in one line?
you know what scope is ?
It does what I want?
Xamie 2020-04-13 21:06:12
Siberfx 2020-04-13 21:02:50
🙂 looking for someone who do it for you or what? :))
Something like that… but more so any complete project…
2020-04-13 21:06:25
yes, it is not bad to write the next one firstOrFail too..
2020-04-13 21:06:36
i did it too
Siberfx 2020-04-13 21:06:40
not necessary
Siberfx 2020-04-13 21:06:55
anyways do it as you like
Siberfx 2020-04-13 21:07:23
I dont use this way, its not clean coding and not fit to what you really want to do
Siberfx 2020-04-13 21:07:44
I would do it only one line
Siberfx 2020-04-13 21:08:06
do yu have debugbar installed ?
2020-04-13 21:08:06
one line?
2020-04-13 21:08:07
how?
2020-04-13 21:08:10
no
Siberfx 2020-04-13 21:08:26
so thats why you will never understand what I mean 🙂
2020-04-13 21:08:28
Telescope isnt good?
Siberfx 2020-04-13 21:09:14
I didnt say that its bad, but why should I use instead debugbar 🙂
2020-04-13 21:09:51
Siberfx 2020-04-13 21:09:14
I didnt say that its bad, but why should I use instead debugbar 🙂
2020-04-13 21:09:58
How do you write it in one line?
Siberfx 2020-04-13 21:10:05
for query optimization, to see how many queries running to fetch all data, bla bla
2020-04-13 21:10:50
Siberfx 2020-04-13 21:10:05
for query optimization, to see how many queries running to fetch all data, bla bla
👍🤦♂️I forgot it,
2020-04-13 21:11:33
I will install it tomorrow, I have just finished my work
Siberfx 2020-04-13 21:12:03
$post = Post::with(‘category’)->whereSlug($slug)->firstOrFail();
Siberfx 2020-04-13 21:12:21
and I would write a scope inside Post model to fetch similar posts
Siberfx 2020-04-13 21:12:38
and use it by single query
2020-04-13 21:12:50
I have one post and the related posts then I did two variables…
Siberfx 2020-04-13 21:13:09
so its not really necessary to have separate queries
Siberfx 2020-04-13 21:13:13
you know what scope is ?
2020-04-13 21:13:22
No🤔
Siberfx 2020-04-13 21:13:30
so thats why 2 lines you write 🙂
2020-04-13 21:13:44
Siberfx 2020-04-13 21:12:03
$post = Post::with(‘category’)->whereSlug($slug)->firstOrFail();
It does what I want?
Siberfx 2020-04-13 21:14:04
this gets only the post with his related category
Siberfx 2020-04-13 21:14:15
but the related posts is not in here.
Siberfx 2020-04-13 21:14:29
for related posts in post model you should create a public function
Siberfx 2020-04-13 21:15:55
something like;
public function scopeSimilarPosts($query) {
return self::whereCategoryId($query->category_id)->get();
}
Siberfx 2020-04-13 21:16:36
then call it in view, foreach ( $post->similiarPosts() as $single) { … }
2020-04-13 21:16:44
Ok, wait.
Siberfx 2020-04-13 21:18:56
and even you can set another relationship to Post hasMany Post according to category_id to category_id
Siberfx 2020-04-13 21:19:01
something like that
Siberfx 2020-04-13 21:19:11
there are several methods you can use
Siberfx 2020-04-13 21:19:22
depends performance issues you can pick the one suits for you
2020-04-13 21:21:44

2020-04-13 21:21:53

2020-04-13 21:22:09

2020-04-13 21:22:10

2020-04-13 21:23:26
I have got a category_id in posts table, but why such error?
Siberfx 2020-04-13 21:23:44
your scope is not the way I wrote
Siberfx 2020-04-13 21:24:09
you querying the single post which is returned,
Siberfx 2020-04-13 21:24:20
and trying to get() of a single post
2020-04-13 21:24:32
Siberfx 2020-04-13 21:23:44
your scope is not the way I wrote
same error
Siberfx 2020-04-13 21:26:01
well do it the way you like
DesolatorMagno 2020-04-13 21:27:07
First do it, them do it right, don’t try to get from 0 to 100, and get half baked knowledge in the way.
2020-04-13 21:29:31
Siberfx 2020-04-13 21:26:01
well do it the way you like
ok, sorry bro