Laravel - mongodb: Difference between revisions
From AWVVO
Jump to navigationJump to search
Line 11: | Line 11: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
== Model == | |||
<syntaxhighlight lang="php" copy line highlight="0"> | <syntaxhighlight lang="php" copy line highlight="0"> | ||
<?php | <?php |
Revision as of 13:56, 5 April 2025
Install mongodb dependency
composer require mongodb/laravel-mongodb
Settings in .env
MONGODB_URI="mongodb+srv://..."
MONGODB_DATABASE="demo"
DB_CONNECTION=mongodb
Model
<?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'
];
}