All Projects → DanielArturoAlejoAlvarez → Eloquent-ORM-Laravel-8.5-Relationships-Advanced

DanielArturoAlejoAlvarez / Eloquent-ORM-Laravel-8.5-Relationships-Advanced

Licence: other
Software of Application with Laravel and MySQL

Programming Languages

PHP
23972 projects - #3 most used programming language
Blade
752 projects
shell
77523 projects

Projects that are alternatives of or similar to Eloquent-ORM-Laravel-8.5-Relationships-Advanced

Borgert Cms
Borgert is a CMS Open Source created with Laravel Framework 5.6
Stars: ✭ 298 (+2028.57%)
Mutual labels:  laravel-framework, bootstrap4
Laravel Form Components
A set of Blade components to rapidly build forms with Tailwind CSS (v1.0 and v2.0) and Bootstrap 4. Supports validation, model binding, default values, translations, Laravel Livewire, includes default vendor styling and fully customizable!
Stars: ✭ 295 (+2007.14%)
Mutual labels:  laravel-framework, bootstrap4
Employee Mgmt Laravel5.4 Adminlte
The project is using laravel 5.4 and adminlte
Stars: ✭ 141 (+907.14%)
Mutual labels:  laravel-framework, bootstrap4
laravel-monitoring
Monitor your Laravel servers
Stars: ✭ 118 (+742.86%)
Mutual labels:  laravel-framework
ace-documentation
A free documentation theme for Hugo, powered by Bootstrap 4. Repsonsive, search, code highlighting and more.
Stars: ✭ 91 (+550%)
Mutual labels:  bootstrap4
mdb4-react-ui-kit
React Bootstrap with Material Design - Powerful and free UI KIT
Stars: ✭ 74 (+428.57%)
Mutual labels:  bootstrap4
blog
基于 Node.js 的个人博客系统. Node.js based blog system.
Stars: ✭ 40 (+185.71%)
Mutual labels:  bootstrap4
laravel-admin
Laravel Admin panel with theme , modules ,artisan commands and helper classess.Laravel admin boilerplate with theme and modules
Stars: ✭ 22 (+57.14%)
Mutual labels:  laravel-framework
LaravelTube
Open source project about sharing videos platform built on Laravel
Stars: ✭ 22 (+57.14%)
Mutual labels:  laravel-framework
OpenAdmin
OpenAdmin - Free Premium Admin Dashboard Theme
Stars: ✭ 87 (+521.43%)
Mutual labels:  bootstrap4
angular5-starter
⭐ An Angular5 Starter Kit :: Router, HttpClient, Forms, Services, Dev/Prod, HMR, Async/Lazy Routes and a very good structure for large applications by @naologic
Stars: ✭ 54 (+285.71%)
Mutual labels:  bootstrap4
finance
💰 Free open-source personal finance tracking web application.
Stars: ✭ 156 (+1014.29%)
Mutual labels:  laravel-framework
Laravel-Trik-Indonesia
Kumpulan trik laravel berbahasa indonesia
Stars: ✭ 74 (+428.57%)
Mutual labels:  laravel-framework
wp-bootstrap4-sass
A clean slate Wordpress theme template with Bootstrap(4) Sass.
Stars: ✭ 28 (+100%)
Mutual labels:  bootstrap4
laravel-lumen-docker
Laravel/Lumen Docker Scaffold
Stars: ✭ 72 (+414.29%)
Mutual labels:  laravel-framework
food-order-app
Simple Food Ordering Website (NodeJS, ExpressJS, MongoDB, Bootstrap) with auto deployment
Stars: ✭ 43 (+207.14%)
Mutual labels:  bootstrap4
bootpack
Create multi-page websites using bootstrap for development and webpack for task running.
Stars: ✭ 30 (+114.29%)
Mutual labels:  bootstrap4
one-bootstrap-template
Flatlogic One - Free Bootstrap Template and Theme
Stars: ✭ 24 (+71.43%)
Mutual labels:  bootstrap4
bootstrap-v4-rtl
Right to Left version of Bootstrap v4.x
Stars: ✭ 101 (+621.43%)
Mutual labels:  bootstrap4
wp-bootstrap4-navwalker
A custom WordPress nav walker class to fully implement the Twitter Bootstrap 4.x navigation style in a custom theme using the WordPress built in menu manager
Stars: ✭ 40 (+185.71%)
Mutual labels:  bootstrap4

ELOQUENT ORM RELATIONSHIPS ADVANCED

Description

This repository is a Software of Application with Laravel.

Installation

Using Laravel 8.5 preferably.

DataBase

Using MySQL preferably. Create a MySQL database and configure the .env file.

Apps

Using Postman,Talend API Tester,Insomnia,etc

Usage

$ git clone https://github.com/DanielArturoAlejoAlvarez/Eloquent-ORM-Laravel-8.5-Relationships-Advanced[NAME APP]

$ composer install

$ copy .env.example .env

$ php artisan key:generate

$ php artisan migrate:refresh --seed

$ php artisan serve

Follow the following steps and you're good to go! Important:

alt text

Coding

Factories

...
public function definition()
    {
        return [
            'level_id'          =>  $this->faker->randomElement([null,1,2,3]),
            'name'              =>  $this->faker->name,
            'email'             =>  $this->faker->unique()->safeEmail,
            'email_verified_at' =>  now(),
            'password'          =>  '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
            'remember_token'    =>  Str::random(10),
        ];
    }
...

Seeders

...
class DatabaseSeeder extends Seeder
{
    /**
     * Seed the application's database.
     *
     * @return void
     */
    public function run()
    {
        // \App\Models\User::factory(10)->create();
        \App\Models\Group::factory(3)->create();


        \App\Models\Level::factory()->create(['name'=>'gold']);
        \App\Models\Level::factory()->create(['name'=>'silver']);
        \App\Models\Level::factory()->create(['name'=>'bronze']);


        \App\Models\User::factory(5)->create()->each(function($user) {
            $profile = $user->profile()->save(\App\Models\Profile::factory()->make());
            $profile->location()->save(\App\Models\Location::factory()->make());

            $user->groups()->attach($this->arrayNum(rand(1,3)));

            $user->image()->save(\App\Models\Image::factory()
                        ->make(['url'=>$this->getAvatar(['men','women'],rand(1,99))]));
        });


        \App\Models\Category::factory(4)->create();
        \App\Models\Tag::factory(12)->create();


        \App\Models\Post::factory(40)->create()->each(function($post) {
            $post->image()->save(\App\Models\Image::factory()->make(['url'=>$this->getPic(rand(1,249))]));
            $post->tags()->attach($this->arrayNum(rand(1,12)));

            $num_comments = rand(1,6);
            for ($i=0; $i < $num_comments; $i++) { 
                $post->comments()->save(\App\Models\Comment::factory()->make());
            }
        });

        \App\Models\Video::factory(40)->create()->each(function($video) {
            $video->image()->save(\App\Models\Image::factory()->make(['url'=>$this->getPic(rand(250,500))]));
            $video->tags()->attach($this->arrayNum(rand(1,12)));

            $num_comments = rand(1,6);
            for ($i=0; $i < $num_comments; $i++) { 
                $video->comments()->save(\App\Models\Comment::factory()->make());
            }
        });

    }

    private function arrayNum($max) {
        $values = [];

        for ($i=1; $i < $max; $i++) { 
            $values[] = $i;
        }

        return $values;
    }

    private function getPic($max) {
        return 'https://picsum.photos/id/'.$max.'/1024/';
    }

    private function getAvatar($arr,$max) {
        $arr_index = array_rand($arr);
        $index = $arr[$arr_index];
        return 'https://randomuser.me/api/portraits/'.$index.'/'.$max.'.jpg';
    }
}
...

Routes

...
Route::get('/', function () {

    $users = App\Models\User::get();
    return view('welcome', ['users'=>$users]);
});

Route::get('/profile/{id}', function($id) {
    $user = App\Models\User::find($id);    
    //dd($user->name);
    
    $posts = $user->posts()
    ->with('category','image','tags')
    ->withCount('comments')->get();
    $videos = $user->videos()
    ->with('category','image','tags')
    ->withCount('comments')->get();

    return view('profile', [
        'user'  =>  $user,
        'posts' =>  $posts,
        'videos'=>  $videos
    ]);
})->name('profile');

Route::get('/level/{id}', function($id) {
    $level = App\Models\Level::find($id);    
    //dd($level->name);
    
    $posts = $level->posts()
    ->with('category','image','tags')
    ->withCount('comments')->get();
    $videos = $level->videos()
    ->with('category','image','tags')
    ->withCount('comments')->get();

    return view('level', [
        'level'  =>  $level,
        'posts' =>  $posts,
        'videos'=>  $videos
    ]);
})->name('level');
...

Models

...
class User extends Authenticatable
{
    use HasFactory, Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'name',
        'email',
        'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast to native types.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function profile() {
        return $this->hasOne(Profile::class);
    }

    public function level() {
        return $this->belongsTo(Level::class);
    }

    public function groups() {
        return $this->belongsToMany(Group::class)->withTimestamps();
    }

    public function location() {
        return $this->hasOneThrough(Location::class, Profile::class);
    }

    public function posts() {
        return $this->hasMany(Post::class);
    }

    public function videos() {
        return $this->hasMany(Video::class);
    }

    public function comments() {
        return $this->hasMany(Comment::class);
    }

    public function image() {
        return $this->morphOne(Image::class, 'imageable');
    }

}
...

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/DanielArturoAlejoAlvarez/Eloquent-ORM-Laravel-8.5-Relationships-Advanced. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.


Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].