shez1983 started a new conversation+100 XP
5mos ago
so i have created an .env.dusk.local, which replaces .env during dusk tests. I can see that happen if i look at the folder in my IDE.
The issue is when i want to check the env, it always returns local.. when it should return testing (which is what i have in my dusk env).
shez1983 wrote a reply+100 XP
5mos ago
but it sounds like h e was working on it and didnt get a chance to save/upload it - in which case git wouldnt have helped..
shez1983 wrote a reply+100 XP
5mos ago
i agree with this ^
shez1983 wrote a reply+100 XP
5mos ago
if its not some topsecret work - share repo/ some code samples for feedback
shez1983 started a new conversation+100 XP
5mos ago
so originally i had a simple Company belongs to country, company has many referrals. then in my INdex, i was displaying one referral per company (based on some criteria)
Now what i want to do is company can belong to many countries. (Ie global/multi national).. so i have added company_country table .. and the referrals ideally should have a company_country_id field.
This is all fine in theory.. but I am having hard time trying to get the referral..
at the moment (pre my changes) i am doing this:
Company::with('country')
->withWhereHas('referral')
->when(!$showAll && !$this->searchGlobally && getStoredCountry(), function($q){
$q->where(function($q){
$q->whereCountryId(getStoredCountry()->id)
->orWhereNull('country_id');
});
})
->when(!$showAll && $this->type, function($q){
$q->whereHas('types', function($q){
$q->whereSlug($this->type);
});
})
->oldest('name')
->get();
what i am trying to do is:
$query = Company::query()
->withWhereHas('referral')
->when(!$showAll && $this->type, function($q){
$q->whereHas('types', function($q){
$q->whereSlug($this->type);
});
});
if ($this->searchGlobally) {
$query->with('randomReferral');
} else if (!$showAll && getStoredCountry()) {
$query->withWhereHas('countries', function($q){
$q->where('country_id', getStoredCountry()->id);
})->with('countries.referral');
}
$this->results = $query->latest('name')->get();
randomReferral and referrals are both a
For now i am doing a simpler thing, and jsut letting users create duplicate companies if country id is different etc so keeping same simpler schema.
shez1983 wrote a reply+100 XP
5mos ago
thanks. pause() doesnt seem to exist, i have tried using waitFor(2). which does.. but that havent worked thus far.
shez1983 started a new conversation+100 XP
5mos ago
So i have a simple test, i m guessing it fails because i have a little bit of logic to update server when user types something..
so what I am having to do is:
visit(route('referrals.create'))
->type('#company', $company->name)
->select('#type_id', '1')
->select('#type_id', '1') // repeat this line again
->screenshot(true) // or do this
->radio('[name="code_or_url_radio"]', 'code')
->fill('#code_or_url', '122234')
->fill('#referrals_commission', '10')
->select('#type_id', '1')
->press('#save')
shez1983 wrote a reply+100 XP
5mos ago
thanks once again - this does help, the only issue is as i have like 6 posts (child component) on the Index page/component, it issues multiple dispatches/events etc..
shez1983 wrote a reply+100 XP
5mos ago
hey - i am having same trouble. did you figure it out?
shez1983 started a new conversation+100 XP
5mos ago
what happens is, when i click on a category to show related posts, it works initially (fresh page load) - but on subsequent click on a different category, if there are 3 results, 2 of them will be related to NEW cat, the third one will be of the previous category.
i use <a wire:click=method(id)>cat</a> to send cat type to component, re-run the search (which is a lot more convulated than a simple, post::whereType..
the QUERY is actually working.. this is my log statements for initial load, u can see collection id [9] ONE result which is totally FINE
mount
render
search
typeid [2]
comp count [{"Illuminate\\Support\\Collection":[9]}]
then when i click on a diff category you can see 6,7,8
updatType
render
search
typeid [1]
comp count [{"Illuminate\\Support\\Collection":[6,7,8]}]
but on the page i see Ids/models : 9, 7, 8, i am doing a
foreach($posts as $post) {
dump($post->id). // HERE corect IDs will be dumped eg 6, 7, 8
<sub component :post=$post> //inside here if i then do $post->id, i will see 9, 7,8
}
HERE is my component:
<?php
namespace ....
use ..
class Index extends Component
{
#[Url]
public ?int $type = null;
#[Url]
public ?string $search = null;
public $types;
public $posts;
public function mount()
{
info('mount');
$this->types = Type::oldest('name')->get();
}
public function render()
{
info('render');
$this->search();
return view('livewire.posts.index');
}
public function updated()
{
info('updated');
$this->search();
}
public function updateType($id)
{
info('updatType');
$this->type = $id;
}
public function search()
{
info('search');
$this->posts = Post::with('country')
//// query
->get();
info('Post count', [$this->posts->pluck('id')]);
}
}
here is my view:
<div class="index">
<div class="filter">
<p>Please choose what you are looking for</p>
<div class="types">
{{ $this->type }}
@foreach($types as $type)
<div class="type">
<a style="cursor: pointer"
wire:click="updateType({{ $type->id }})"
{{-- href="{{ route('posts.index', ['type' => $type->slug]) }}" --}}
>
<img src="{{ asset($type->image) }}"/>
{{ $type->name }}
</a>
</div>
@endforeach
</div>
</div>
<div class="posts">
@foreach ($posts as $post)
@dump($post->id)
<livewire:posts.card :post="$post"/>
@endforeach
</div>
</div>
here is the post card: (child)
<div class="post">
<img src="{{ asset($post->image) }}"/>
{{ $post->name }}<br/>
{{ $post->id }}<br/>
</div>