shez1983 started a new conversation+100 XP
2mos ago
shez1983 started a new conversation+100 XP
2mos 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
2mos ago
shez1983 started a new conversation+100 XP
2mos 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
3mos ago
shez1983 wrote a reply+100 XP
3mos ago
shez1983 started a new conversation+100 XP
3mos 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>
shez1983 wrote a reply+100 XP
3mos ago
the issue was that i had a style tag... (when i converted the single annon to an older syntax with class and view separate, I added style tag at the top of view.. and that was messing up..
altho i am not 100% sure why my example code wasnt working... i am just happy I got it working, was driving me nuts
shez1983 started a new conversation+100 XP
3mos ago
So I have a component, with Class and view separate. in class on mount i do
$c. = Model::query()...
and use that in view just fine.
The issue is if i do .. nothing happens, if i submit a form, it just refreshes the page?
I have created a new LARAVEL install with livewire.. i tried adding @livewireScripts as those were missing and no luck..
[I do have a livewire3 app which is working fine, and i cant see any major diff between that and this, apart from in composer.json where this new app explicitly requires livewire.. wheras in the old one i just see livewire/volt entry, and yes i have tried to duplicate that in my new app.. [
also initially i created the new livewire pages:: (with anon class at the top, view at bottom ,kinda like vueJS setup) and that didnt work either..
new class extends Component
{
public ?int $countryId = null;
public ?int $typeId = null;
public ?string $search = null;
public $countries;
public $types;
public $results;
public function mount()
{
$this->countries = ''
$this->types = ''
$this->countryId = ''
$this->search();
}
public function updatedCountryId($value)
{
info('updating country id');
}
public function search()
{
$this->results = R::get();
}
};
?>
<div>
<div class="filters">
<form wire:submit.prevent='search'>
<label>Countries</label>
<select wire:model='countryId'>
<option value="">--Select--</option>
@foreach ($countries as $country)
<option value="{{ $country->id }}" >
{{ $country->name }}
</option>
@endforeach
</select>
<label>Category</label>
<select wire:model='typeId'>
<option value="">--Select--</option>
@foreach ($types as $type)
<option
@selected($typeId === $type->id)
value="{{ $type->id }}"
>
{{ $type->name }}
</option>
@endforeach
</select>
<label>Search</label>
<input wire:model='search'/>
<input type="submit" value="search" wire:click='search'/>
</form>
</div>
<div class="results">
@foreach ($results as $result)
<div class="result">
///
</div>
@endforeach
</div>
</div>
shez1983 started a new conversation+100 XP
5mos ago
$browser ->fillForm($post, [$field]) ->screenshot('debug 1') ->press('@submit') ->waitFor('@' . $field . '-error', 10); ;
so notice i have screenshot() there.. if i remove that this test will fail. it leads me to think that the delay is needed somehow.. funny thing is delay should be added AFTER i press submit to give it time to process and show error..
in other tests - i have also had to manually add sleep() to pass the test.
is there any solution?
shez1983 wrote a reply+100 XP
5mos ago
shez1983 started a new conversation+100 XP
5mos ago
so I am trying to add this package, not sure if its relevant https://github.com/wire-elements/modal
on my layouts page I add following as suggested.
@livewire('wire-elements-modal')
i then create a modal open link
<a wire:click.prevent="$dispatch('openModal', { component: 'update-modal', arguments: { post: '{{ $post->slug }}' }})"
class="drop-li cursor-pointer"
>
when i click on this link i get
javascript?v=1753192890:2038 POST http://url.test/livewire/update 404 (Not Found)
thing is when i navigate to the page - i can see livewire IS working as that page is a component - and component actions are working
shez1983 wrote a reply+100 XP
5mos ago
shez1983 started a new conversation+100 XP
5mos ago
$browser
->visit(route('posts.show', ['post' => $old->slug]))
->screenshot(1)
->assertRouteIs(route('posts.show', ['posts' => $old->slug]));
so when i see screenshot, I can see dusk has gone to the url - ie correct screenshot.. however assertRoute is.. returns
Route [http://laravel.test/posts/environment-neque-as-6914e1669609c] not defined.
at vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:526
522▕ ! is_null($url = call_user_func($this->missingNamedRouteResolver, $name, $parameters, $absolute))) {
523▕ return $url;
524▕ }
525▕
➜ 526▕ throw new RouteNotFoundException("Route [{$name}] not defined.");
527▕ }
528▕
529▕ /**
530▕ * Get the URL for a given route instance.