Member Since 2 Years Ago
4,800 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 Unit Tests - RuntimeException : A Facade Root Has Not Been Set.
Martin, if you're still out there... :)
use App\Models\Fees\UsersSubscription;
use App\User;
use Faker\Generator as Faker;
use Illuminate\Support\Str;
$factory->define(UsersSubscription::class, function (Faker $faker) {
return [
'user_id' => User::Factory(),
'fee_id' => Fee::Factory(),
'active' => '1',
'renew' => '1',
'tcs_version' => '1',
'existing_customer' => 1
];
});
My factories are 7.x style now. But when I do this...
$user = factory(User::class)
->create()
->each(function ($u) {
$u->usersSubscription()->save(factory(UsersSubscription::class)->make());
});
I get this
BadMethodCallException : Call to undefined method App\User::Factory()
...but it works if I do this...
$user = factory(User::class)
->create();
I should have been a lumberjack...
Replied to Unit Tests - RuntimeException : A Facade Root Has Not Been Set.
version 7.x here - I must have not checked the version of the docs before I started taking bits.
Thanks !
Replied to Unit Tests - RuntimeException : A Facade Root Has Not Been Set.
Thanks Martin, I am very much new to this so appreciate your help.
I now get the following error :
InvalidArgumentException : Unable to locate factory for [App\User].
I have this in database\factories\UserFactory.php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factory;
use Illuminate\Support\Str;
use App\User;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'first_name' => $this->faker->name,
'last_name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'email_verified_at' => now(),
'password' => 'yIXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
];
}
}
Any further help would get me out of trouble, many thanks.
Replied to Unit Tests - RuntimeException : A Facade Root Has Not Been Set.
Hi Martin
Sorry for my imprecise language, assuming that I want to do this as a feature test, and I still get this error, what should I do then ?
Started a new Conversation Unit Tests - RuntimeException : A Facade Root Has Not Been Set.
Hi, I'm trying to create a factory to use in a unit test.
$user = factory(User::class, 1)->create()->each(function($u) {
$u->usersSubscription()
->save( factory(UsersSubscription::class)->make() )
->each(function($p){
$p->usersSubscriptionFeesCollection()->save(factory(UsersSubscriptionFeesCollection::class)->make());
});
});
and I get this error :
RuntimeException : A facade root has not been set.
Any help would be gratefully received.
Replied to Eloquent - Where Clause In Anonymous Function Not Behaving As Expected
It turns out you were right ! Once I'd added the where into the second clause, all was working.
Many thanks for your help.
Started a new Conversation Eloquent - Where Clause In Anonymous Function Not Behaving As Expected
Hi, I was hoping to get some advice on this innocuous piece of eloquent :
$users = User::with(['usersSubscriptionFeesCollection' => function ($q) use ($value) {
$q->where('settled','=','0');
}])
->with(['usersSubscription' => function ($q) use ($value) {
$q->('active', '=', '1');
}])
->where('active', '=', '1')
->get();
I expect the output of this to be the active users, the active userSubscriptions for the users, and the unsettled (settled = 0) usersSubscriptionFeesCollection for the userSubscriptions.
For some reason the output for this collection includes usersSubscriptionFeesCollection records with settled = 1 aswell as settled = 0. Oddly, the second with clause does behave as expected (only giving active usersSubscriptions.
If any patient developers can explain why this might happen, I'd be extremely grateful.