Member Since 4 Years Ago
1,810 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 Very Very Slow Api Requests On Homestead
Yeah, that’s what I’m trying to figure out. My vm is pretty high spec and certainly shouldn’t struggle to make a post request. Wondered if it might be some weird homestead thing that needs a tweak
Replied to Very Very Slow Api Requests On Homestead
thing is, other api calls are ok - just seems to be the azure ones
Started a new Conversation Very Very Slow Api Requests On Homestead
Does anyone know why an api call to Azure would take 20 seconds to return a response on homestead but when I push to production server it is almost instant?
Replied to N+1 Issue
Not sure of your relationship setup but I think you may not actually be eager loading as you think. Try this...
$payment = Payment::with(['expense_reports.expenses' ])
Awarded Best Reply on Livewire Not Working
Also try publishing assets if you haven’t already
php artisan livewire:publish --assets
Awarded Best Reply on Livewire Do Not Show The Data With Out The Page Reload
I’m on my phone at the minute so can’t really type loads of code. It isn’t really a livewire thing, if you know php and/or laravel you can do it. I think you can just add $comment = Comment::create...
Then array_push($this->comments, $comment)
Replied to Mass Assignment Query
Just spotted the user_id - the first answer @michaloravec gave is better than mine
Replied to Mass Assignment Query
Page::create($request->all());
but you really should validate and then do Page::create($validated);
You can also append to $validated before you create:
$validated[‘uri’] = Str::slug($request->input('title'), '-');
Replied to How To Get To Tenants Data Throw Central Admin Panel ?
tenancy()->initialize($tenant);
then run your tenant code
$tenant is the desired tenant model eg Tenant::find(‘my tenant’)
When you are done tenancy()->end()
to switch back to central
Replied to Livewire Not Working
Also try publishing assets if you haven’t already
php artisan livewire:publish --assets
Replied to Livewire Do Not Show The Data With Out The Page Reload
I’m on my phone at the minute so can’t really type loads of code. It isn’t really a livewire thing, if you know php and/or laravel you can do it. I think you can just add $comment = Comment::create...
Then array_push($this->comments, $comment)
Replied to Livewire Do Not Show The Data With Out The Page Reload
This will work but means you are querying all comments every time. You only need to add the new comment to the existing var
Replied to Livewire Do Not Show The Data With Out The Page Reload
After creating the comment you need to push the new comment onto your $this->comments array
Replied to Livewire Not Working
I agree with tykus about the mount(). No need to keep querying the database for the skills.
Assuming your code provided was complete, you need to wrap your livewire blade code in a div otherwise expect unexplained nothingness
Replied to Re-use QueryScope As Attribute
Happy to use the scope in the query so long as I can still retrieve all the results - this is where I thought that during the query the scope could be used in a subquery to set a custom 'overdue: bool' property on each result.
Feels a bit wrong repeating a lot of logic, one for a scope and one for the accessor
Replied to Re-use QueryScope As Attribute
Just wondered if the scope could somehow be reused on the collection or if it can set a custom attribute like withCount()
Started a new Conversation Re-use QueryScope As Attribute
I have a pretty complex query scope scopeIsOverdue
. I also need a getIsOverdueAttribute
. Is there a way I can reuse the query scope for this rather than try and mimic the scopes logic again
The query scope will limit the results to just the overdue ones. I want to be able to still show all results but have a way to also identify an overdue row
So basically:
$results = Model::query()->isOverdue()
returns only overdue results (currently works)
$results = Model::all()
returns all results (currently works)
Then I want to be able to do something along the lines of....
$results->first()->isOverdue()
Should be true or false (or 0 or 1)
Awarded Best Reply on Validate Field :: Error Message Not Appearing In View
Replied to Issue With Laravel Policy
I am sure I remember reading something in the spatie docs about avoiding naming a permission the same as a policy, so if you have a permission called “create” and a policy of the same name it will cause issues
Replied to Transaction Not Working As Expected
It does run the insert() on both examples though, just not the delete(). Wondering if it has to be a separate transaction per 'transaction'? If that is the case, I don't want to commit the delete unless the insert has worked
Started a new Conversation Transaction Not Working As Expected
When I run this, fees are inserted but the delete is ignored
DB::beginTransaction();
try {
$this->fees()->delete();
Fee::insert($data);
DB::commit();
} catch (\exception $ex) {
DB::rollback();
}
When I run this, it works as expected i.e. deletes all fees, then inserts new ones
$this->fees()->delete(); //moved outside of transaction
DB::beginTransaction();
try {
Fee::insert($data);
DB::commit();
} catch (\exception $ex) {
DB::rollback();
}
What am I missing? I don't really want it to delete anything if the insert fails
Replied to 2 Laravel Apps Sharing Login
that looks good - just wondering now as I just realised I will probably want separate php versions for each laravel install if I host them on two completely separate servers and use database sessions, can I still do this. Maybe have to resort to the subdomain though
Replied to 2 Laravel Apps Sharing Login
Yes, digital ocean and nginx. I don't want to use a subdomain if I can help it.
Replied to 2 Laravel Apps Sharing Login
Thanks. So if I run it in a subdirectory, would the session just work across both copies without the need to change anything config-wise?
Do you know how I would go about making the subdirectory version?
Replied to 2 Laravel Apps Sharing Login
there will only be one login form and that is on the main app. The thing I want to ensure is that the logged in session persists across both apps. Also, can I run a second copy of laravel on the same domain in a subdirectory?
Started a new Conversation 2 Laravel Apps Sharing Login
I have a large app on 5.1 and have to build a large additional section which I want to do in v8 as upgrading the whole thing isn't possible at the moment. The plan is to build the additional section to read from the same database but it needs to be behind the same login i.e. login on main app also logs you in on the v8 part.
Happy to put both on the same server but would be nice if that wasn't a requirement.
Couple of questions...
Thanks
Replied to Conditional Renderng Wire:click
Give more context, show more code and tell us what you mean by “not working”.
I suspect what you probably need to do is lose the condition altogether and use form validation instead inside your live wire controller. That is assuming you don’t want the form to submit unless a gdpr checkbox has been ticked?
Replied to How To Pass Array As Second Parameter In Livewire Function
It JS, you need to implode it then explode within your controller
Replied to Filesystems.php - Read Only?
I've never actually used it myself but if you were to store 3 files with the above config on local driver:
Storage::put('secret.txt', 'hello', 'private');; // file created will be read/write but no access for guests/everyone
Storage::put('web.txt', 'hello', 'public');; // file will be read/write but readonly for guests/everyone
Storage::put('read.txt', 'hello', 'readonly'); // file created will be readonly
Replied to Getting Stancl/tenancy Working Per Domain In Homestead
could you try a tenant with a .test extension? I think its just the .localhost that is causing the issue
Replied to Getting Stancl/tenancy Working Per Domain In Homestead
so, domains are set up in hosts file, and yaml file, and your central database 'domains' table shows both of those domains, and both tenant tables exist and have migrated? If so and it still isn't working you might need to check your log files to find the cause
One thing to consider...I'm not so sure you can use localhost as a domain extension - I would try something like foo.test and bar.test as your tenant domains - I get the same error as you if I try and visit foo.localhost but foo.anythingelse gives a completely different error
Replied to Getting Stancl/tenancy Working Per Domain In Homestead
Did you reload homestead server to pick up the changes?
vagrant reload --provision
Replied to Getting Stancl/tenancy Working Per Domain In Homestead
ah sorry, yes you do need to add them to your yaml file.
map: ats.test
to: /home/vagrant/code/public
map: foo.localhost
to: /home/vagrant/code/public
map: bar.localhost
to: /home/vagrant/code/public
Replied to Getting Stancl/tenancy Working Per Domain In Homestead
No, just the hosts file. Did you check that the databases have been created for the tenants and the domains are definitely correct?
Replied to Filesystems.php - Read Only?
I think you can add a custom permission level...
https://laravel.com/docs/8.x/filesystem#local-files-and-visibility
'dir' => [
'public' => 0775,
'private' => 0700,
'readonly' => 0444,
],
Replied to Getting Stancl/tenancy Working Per Domain In Homestead
You just add them to your hosts file too on the same ip
192.168.10.10 ats.test
192.168.10.10 foo.localhost
192.168.10.10 bar.localhost
Started a new Conversation Mailhog On Staging With Auth?
Does anyone know a good way of using mailhog with laravel on a staging server and making it password protected so the client can freely test out an app without worrying about using real email addresses but still be able to read the emails that it sends out?
Started a new Conversation Order By Date Desc Time Asc
Is there an elqouent way to order by date and time separately. e.g. created_at
order by date desc, time asc
Awarded Best Reply on Laravel Event Subscriber Error
If it works on local and production, where is it not working? It looks like that eloquent query is not returning a result, or it is not returning a result with an orderProduct
. So you need to debug your query and make sure for that record the data is in the database.
Steps I would take (assuming this is one item and not part of a loop):
dd($pharmacyEvent->prescription->product_id)
dd($stock)
whereHas()
and the whereNull()
parts of the queryThat should hopefully highlight the issue
Replied to User Factory Has Relation Only If User Type = X
ah never mind...I changed it slightly and it worked...
public function configure()
{
return $this->afterMaking(function (User $user) {
})->afterCreating(function (User $user) {
$user->posts()->save(Post::factory()->make());
});
}
Replied to User Factory Has Relation Only If User Type = X
It's in my original post. ^ That is the seeder.
User has many posts.
The user factory:
public function definition()
{
return [
'name' => $name,
'type' => $this->faker->randomElement(['author', 'client']),
];
}
So basically trying to do this:
$user = User::factory()
->times(1000)
// if($user->type == 'author')
->has(Post::factory(), 'posts')
// endif
->create()
I tried adding this to my UserFactory but got "unable to locate factory for App\Post:
public function configure()
{
return $this->afterMaking(function (User $user) {
})->afterCreating(function (User $user) {
$user->posts()->save(factory(Post::class)->make());
});
}
Started a new Conversation User Factory Has Relation Only If User Type = X
If I have a UserFactory with a random selection of user types, how can I write this so that it creates 1000 users, but only users with $user->type == 'author' will have a post created.
As it stands, every user gets a post which isn't ideal.
User::factory()->times(1000)->has(Post::factory(), 'posts')->create()
Replied to CSV League - Expecting Array Got Object
Looks like you need to fetch the db results:
$query = DB::connection('reporting')->select('
select * from users
')->get();
Replied to Laravel Event Subscriber Error
If it works on local and production, where is it not working? It looks like that eloquent query is not returning a result, or it is not returning a result with an orderProduct
. So you need to debug your query and make sure for that record the data is in the database.
Steps I would take (assuming this is one item and not part of a loop):
dd($pharmacyEvent->prescription->product_id)
dd($stock)
whereHas()
and the whereNull()
parts of the queryThat should hopefully highlight the issue
Replied to Won't Let Me Log In After Changing Password
Try dd($request->nyttpassord)
after your save() to make sure that what you are typing is actually what is being stored