[email protected] liked a comment+100 XP
5mos ago
[email protected] liked a comment+100 XP
5mos ago
[email protected] liked a comment+100 XP
5mos ago
@snapey I think he means his IDE (phpstorm) reports the findOrFail method is not found, not that it won't work if executed.
@Viernes Laravel uses lots of magic behind the scenes that a lot of IDE's can't pick up on.
In phpstorm, make sure you have the laravel plugin installed and enabled. Also, this package will help phpstorm find a lot of the magic that the IDE can't figure out: https://github.com/barryvdh/laravel-ide-helper
[email protected] wrote a comment+100 XP
5mos ago
OK, adding pivot table records (that make sense with the job title!), I did it in DBSeeder like this
\App\Models\Job::factory(20)->create(); // will make an employer as well for each job
// create 6 known tags (likely to be present in the 20 fake job titles!)
\App\Models\Tag::factory()
->count(6)
->sequence(
[ 'name' => 'Operator'],
[ 'name' => 'Manager'],
[ 'name' => 'Technician'],
[ 'name' => 'Supervisor'],
[ 'name' => 'Worker'],
[ 'name' => 'Support']
)
->create();
// create job-tag pivot records for any jobs that have a tag name as part of the job title
foreach (\App\Models\Tag::all() as $tag) {
foreach (\App\Models\Job::all() as $job) {
if (str_contains($job->title,$tag->name)) {
$job->tags()->attach($tag->id);
}
}
}
}
[email protected] liked a comment+100 XP
5mos ago
i think it is too late, but if somebody will search this solution:
https://laravel.com/docs/10.x/eloquent-factories#sequences
you can just use sequence() method:
$users = User::factory()
->count(2)
->sequence(
['name' => 'First User'],
['name' => 'Second User'],
)
->create();
[email protected] wrote a comment+100 XP
5mos ago
@aztec_gold How to seed a pivot table - good question, I am wondering same thing. the job_tag table is created inside the create_tags_table migration sp it will exist once the migrations are run, but there is no model for it... so how to reference in the seeder? And of course need to have some seeder logic to create tags and the associate to job...
Aah, see comment by @bjoernzosel for one way
[email protected] liked a comment+100 XP
5mos ago
[email protected] liked a comment+100 XP
5mos ago
@Adam_S You can use command + right arrow it will move your cursor to the end of the line :)
[email protected] wrote a comment+100 XP
5mos ago
@cblack267 HeidiSQL works well, pretty siilar to tableplus, and free! As Jeffrey said, "lots of tools , choose one"