本文整理汇总了PHP中app\models\Language::create方法的典型用法代码示例。如果您正苦于以下问题:PHP Language::create方法的具体用法?PHP Language::create怎么用?PHP Language::create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Language
的用法示例。
在下文中一共展示了Language::create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$now = date('Y-m-d H:i:s', strtotime('now'));
$languages = [['name' => 'english', 'description' => 'the Language English', 'created_at' => $now, 'updated_at' => $now], ['name' => 'danish', 'description' => 'the Language Danish, spoken in Denmark', 'created_at' => $now, 'updated_at' => $now], ['name' => 'pashto', 'description' => 'the Language Pashto, spoken in Afghanistan', 'created_at' => $now, 'updated_at' => $now]];
foreach ($languages as $language) {
if (\App\Models\Language::where('name', '=', $language['name'])->exists()) {
echo $language['name'] . " Already exists\n";
} else {
\App\Models\Language::create($language);
}
}
//DB::table('words')->truncate();
//Schema::drop('words');
$passed = 0;
$exists = 0;
//word table - seed from a file
// $pashto_json = File::get(storage_path() . "/app/json_data/pashto.json");
// $pashto_word = json_decode($pashto_json);
//
// foreach ($pashto_word as $wordObj)
// {
// if(\App\Models\Word::where('word', '=', $wordObj->s2p[0])->exists())
// {
// echo $wordObj->s2p[0] . " Already exists\n";
// $exists++;
// }
// else
// {
// \App\Models\Word::create([
// 'language_id' => 3,
// 'user_id' => 3,
// 'word' => $wordObj->s2p[0],
// 'pronounce_audio_path' => '',
// 'pronounce_text' => 'pronounce_text missing',
// 'definition' => 'Word definition missing',
// 'created_at' => $now,
// 'updated_at' => $now,
// ]);
//
// $passed++;
// }
// }
foreach (File(storage_path() . "/app/danskOrde_49389.txt", FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES) as $word) {
if (App\Models\Word::where(['language_id' => 2, 'word' => $word])->exists()) {
echo $word . ": Already exists in Danish\n";
$exists++;
} else {
App\Models\Word::create(['language_id' => 2, 'user_id' => 3, 'word' => $word, 'pronounce_audio_path' => '', 'pronounce_text' => 'pronounce_text missing', 'definition' => 'Word definition missing', 'created_at' => $now, 'updated_at' => $now]);
$passed++;
}
}
echo "\n Words Already Exists: " . $exists;
echo "\n Words added: " . $passed . "\n";
}
示例2: run
public function run()
{
Eloquent::unguard();
$languages = [['name' => 'English', 'locale' => 'en'], ['name' => 'Italian', 'locale' => 'it'], ['name' => 'German', 'locale' => 'de'], ['name' => 'French', 'locale' => 'fr'], ['name' => 'Brazilian Portuguese', 'locale' => 'pt_BR'], ['name' => 'Dutch', 'locale' => 'nl'], ['name' => 'Spanish', 'locale' => 'es'], ['name' => 'Norwegian', 'locale' => 'nb_NO'], ['name' => 'Danish', 'locale' => 'da'], ['name' => 'Japanese', 'locale' => 'ja'], ['name' => 'Swedish', 'locale' => 'sv'], ['name' => 'Spanish - Spain', 'locale' => 'es_ES'], ['name' => 'French - Canada', 'locale' => 'fr_CA'], ['name' => 'Lithuanian', 'locale' => 'lt'], ['name' => 'Polish', 'locale' => 'pl'], ['name' => 'Czech', 'locale' => 'cs']];
foreach ($languages as $language) {
$record = Language::whereLocale($language['locale'])->first();
if ($record) {
$record->name = $language['name'];
$record->save();
} else {
Language::create($language);
}
}
Eloquent::reguard();
}
示例3: run
public function run()
{
Eloquent::unguard();
// https://github.com/caouecs/Laravel-lang
// https://www.loc.gov/standards/iso639-2/php/code_list.php
$languages = [['name' => 'English', 'locale' => 'en'], ['name' => 'Italian', 'locale' => 'it'], ['name' => 'German', 'locale' => 'de'], ['name' => 'French', 'locale' => 'fr'], ['name' => 'Brazilian Portuguese', 'locale' => 'pt_BR'], ['name' => 'Dutch', 'locale' => 'nl'], ['name' => 'Spanish', 'locale' => 'es'], ['name' => 'Norwegian', 'locale' => 'nb_NO'], ['name' => 'Danish', 'locale' => 'da'], ['name' => 'Japanese', 'locale' => 'ja'], ['name' => 'Swedish', 'locale' => 'sv'], ['name' => 'Spanish - Spain', 'locale' => 'es_ES'], ['name' => 'French - Canada', 'locale' => 'fr_CA'], ['name' => 'Lithuanian', 'locale' => 'lt'], ['name' => 'Polish', 'locale' => 'pl'], ['name' => 'Czech', 'locale' => 'cs'], ['name' => 'Croatian', 'locale' => 'hr'], ['name' => 'Albanian', 'locale' => 'sq']];
foreach ($languages as $language) {
$record = Language::whereLocale($language['locale'])->first();
if ($record) {
$record->name = $language['name'];
$record->save();
} else {
Language::create($language);
}
}
Eloquent::reguard();
}
示例4: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::statement("SET foreign_key_checks = 0");
Language::truncate();
Language::create(['language_name' => 'Marathi']);
Language::create(['language_name' => 'Hindi']);
Language::create(['language_name' => 'Bengali']);
Language::create(['language_name' => 'Tamil']);
Language::create(['language_name' => 'Telugu']);
Language::create(['language_name' => 'Malyalam']);
Language::create(['language_name' => 'Bhojpuri']);
Language::create(['language_name' => 'Maithili']);
Language::create(['language_name' => 'Punjabi']);
Language::create(['language_name' => 'Haryani']);
Language::create(['language_name' => 'Gujrati']);
Language::create(['language_name' => 'Odiya']);
Language::create(['language_name' => 'Tulu']);
}