Laravel - mongodb: Difference between revisions

From AWVVO
Jump to navigationJump to search
Created page with "== Install mongodb dependency == <syntaxhighlight lang="bash" copy line highlight="0"> composer require mongodb/laravel-mongodb </syntaxhighlight> == Settings in .env == <syntaxhighlight lang="yaml" copy line highlight="0"> MONGODB_URI="mongodb+srv://..." MONGODB_DATABASE="demo" DB_CONNECTION=mongodb </syntaxhighlight>"
 
Line 3: Line 3:
composer require mongodb/laravel-mongodb
composer require mongodb/laravel-mongodb
</syntaxhighlight>
</syntaxhighlight>
== Install dependency ==
<syntaxhighlight lang="bash" copy line highlight="0">
composer require mongodb/laravel-mongodb
</syntaxhighlight>aText Premium


== Settings in .env ==
== Settings in .env ==
Line 9: Line 14:
MONGODB_DATABASE="demo"
MONGODB_DATABASE="demo"
DB_CONNECTION=mongodb
DB_CONNECTION=mongodb
</syntaxhighlight>
<syntaxhighlight lang="php" copy line highlight="0">
<?php
namespace App\Models;
use MongoDB\Laravel\Eloquent\Model;


class Film extends Model
{
    //protected $connection = 'mongodb';
    protected $collection = 'films';
    protected $fillable = [
        'title',
        'year',
        'genre',
        'director',
        'actors',
        'plot',
        'poster',
        'rating'
    ];
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 13:55, 5 April 2025

Install mongodb dependency

composer require mongodb/laravel-mongodb

Install dependency

composer require mongodb/laravel-mongodb

aText Premium

Settings in .env

MONGODB_URI="mongodb+srv://..."
MONGODB_DATABASE="demo"
DB_CONNECTION=mongodb
<?php

namespace App\Models;

use MongoDB\Laravel\Eloquent\Model;

class Film extends Model
{
    //protected $connection = 'mongodb';
    protected $collection = 'films';
    protected $fillable = [
        'title',
        'year',
        'genre',
        'director',
        'actors',
        'plot',
        'poster',
        'rating'
    ];
}