Search
 
SCRIPT & CODE EXAMPLE
 

PHP

laravel eloquent relationships

<?php

namespace AppModels;

use IlluminateDatabaseEloquentModel;

class Project extends Model
{
    /**
     * Get all of the deployments for the project.
     */
    public function deployments()
    {
        return $this->hasManyThrough(Deployment::class, Environment::class);
    }
}
Comment

eloquent relationships

$roles = AppUser::find(1)->roles()->orderBy('name')->get();
Comment

laravel eloquent relationships

?
<?php
 
use IlluminateDatabaseSeeder;
use IlluminateDatabaseEloquentModel;
 
class DatabaseSeeder extends Seeder {
 
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        Model::unguard();
  
        for ($i = 1; $i < 11; $i++) {
            DB::table('categories')->insert(['name' => 'Category ' . $i]);
            DB::table('periods')->insert(['name' => 'Period ' . $i]);
            DB::table('countries')->insert(['name' => 'Country ' . $i]);
        }
  
        for ($i = 1; $i < 21; $i++) {
            DB::table('themes')->insert(['name' => 'Theme ' . $i]);
            DB::table('editors')->insert(['name' => 'Editor ' . $i]);
            DB::table('formats')->insert(['name' => 'Format ' . $i]);
            DB::table('contacts')->insert(['phone' => '00 00 00 00 00', 'editor_id' => $i]);
            DB::table('cities')->insert(['name' => 'City ' . $i, 'country_id' => rand(1, 10)]);
        }
  
        for ($i = 1; $i < 21; $i++) {
            DB::table('authors')->insert(['name' => 'Author ' . $i, 'city_id' => rand(1, 20)]);
        }
  
        for ($i = 1; $i < 51; $i++) {
            $choice = array('AppModelsFormat','AppModelsEditor');
            DB::table('books')->insert([
                'name' => 'Book ' . $i,
                'bookable_id' => rand(1, 20),
                'theme_id' => rand(1, 20),
                'bookable_type' => $choice[rand(0,1)]
            ]);
        }
 
        for ($i = 1; $i < 21; $i++) {
            $number = rand(2, 8);
            $items = [];
            for ($j = 1; $j <= $number; $j++) {
                while(in_array($n = rand(1, 50), $items)) {}
                $items[] = $n;
                DB::table('author_book')->insert(array(
                    'book_id' => $n,
                    'author_id' => $i
                ));
            }
        }
  
        $items = [];
        for ($i = 1; $i < 81; $i++) {
            $choice = array('AppModelsCategory','AppModelsPeriod');
            do{
                $t1 = rand(1, 20);
                $t2 = rand(1, 20);
                $t3 = $choice[rand(0,1)];
            } while(in_array($t1 . $t2 . $t3, $items));
            $items[] = $t1 . $t2 . $t3;
            DB::table('themables')->insert([
                'theme_id' => $t1,
                'themable_id' => $t2,
                'themable_type' => $t3
            ]);
        }
    }
 
}
Comment

PREVIOUS NEXT
Code Example
Php :: woocommerce custom payment process method 
Php :: php echo statement 
Php :: laravel set middleware default 
Php :: open phpstorm from terminal 
Php :: php string remove last character 
Php :: php override built in functions 
Php :: all() in laravel 
Php :: split functions.php 
Php :: header in fpdi 
Php :: php array form 
Php :: Change the colorbar scale to log scale 
Php :: php how to check if user has a role on login 
Php :: put_assoc 
Php :: Mirror Inverse Program in php 
Php :: storefront product search 
Php :: Problem getting updated value from child component to the parent component in a Laravel 9 with Vue 
Php :: laravel remove public from url htaccess 
Php :: cpt change link 
Php :: how to change php to html 
Php :: php mysql text mark question 
Php :: laravel request 
Php :: acf advanced link 
Php :: how to fix Undefined variable: product (View: C:xampphtdocsecommerce esourcesviewslivewireshop-component.blade.php) 
Php :: PHP strpbrk — Search a string for any of a set of characters 
Php :: create global function laravel 
Php :: how can i get input id in laravel 8 
Php :: laravel Add a static label/text above panel 
Php :: laravel belongsto with condition date 
Php :: Obtener rol de usuario registrado en WordPress 
Php :: wordpress get posts by multiple authors 
ADD CONTENT
Topic
Content
Source link
Name
4+7 =